idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
7,100
public static function getPicklistFacts ( $ fact_type ) : array { switch ( $ fact_type ) { case 'INDI' : $ tags = [ 'RESN' , 'NAME' , 'SEX' , 'BIRT' , 'CHR' , 'DEAT' , 'BURI' , 'CREM' , 'ADOP' , 'BAPM' , 'BARM' , 'BASM' , 'BLES' , 'CHRA' , 'CONF' , 'FCOM' , 'ORDN' , 'NATU' , 'EMIG' , 'IMMI' , 'CENS' , 'PROB' , 'WILL' , 'GRAD' , 'RETI' , 'EVEN' , 'CAST' , 'DSCR' , 'EDUC' , 'IDNO' , 'NATI' , 'NCHI' , 'NMR' , 'OCCU' , 'PROP' , 'RELI' , 'RESI' , 'SSN' , 'TITL' , 'FACT' , 'BAPL' , 'CONL' , 'ENDL' , 'SLGC' , 'SUBM' , 'ASSO' , 'ALIA' , 'ANCI' , 'DESI' , 'RFN' , 'AFN' , 'REFN' , 'RIN' , 'CHAN' , 'NOTE' , 'SHARED_NOTE' , 'SOUR' , 'OBJE' , '_BRTM' , '_DEG' , '_DNA' , '_EYEC' , '_FNRL' , '_HAIR' , '_HEIG' , '_HNM' , '_HOL' , '_INTE' , '_MDCL' , '_MEDC' , '_MILI' , '_MILT' , '_NAME' , '_NAMS' , '_NLIV' , '_NMAR' , '_PRMN' , '_TODO' , '_UID' , '_WEIG' , '_YART' , ] ; break ; case 'FAM' : $ tags = [ 'RESN' , 'ANUL' , 'CENS' , 'DIV' , 'DIVF' , 'ENGA' , 'MARB' , 'MARC' , 'MARR' , 'MARL' , 'MARS' , 'RESI' , 'EVEN' , 'NCHI' , 'SUBM' , 'SLGS' , 'REFN' , 'RIN' , 'CHAN' , 'NOTE' , 'SHARED_NOTE' , 'SOUR' , 'OBJE' , '_NMR' , 'MARR_CIVIL' , 'MARR_RELIGIOUS' , 'MARR_PARTNERS' , 'MARR_UNKNOWN' , '_COML' , '_MBON' , '_MARI' , '_SEPR' , '_TODO' , ] ; break ; case 'SOUR' : $ tags = [ 'DATA' , 'AUTH' , 'TITL' , 'ABBR' , 'PUBL' , 'TEXT' , 'REPO' , 'REFN' , 'RIN' , 'CHAN' , 'NOTE' , 'SHARED_NOTE' , 'OBJE' , 'RESN' , ] ; break ; case 'REPO' : $ tags = [ 'NAME' , 'ADDR' , 'PHON' , 'EMAIL' , 'FAX' , 'WWW' , 'NOTE' , 'SHARED_NOTE' , 'REFN' , 'RIN' , 'CHAN' , 'RESN' , ] ; break ; case 'PLAC' : $ tags = [ 'FONE' , 'ROMN' , '_HEB' , ] ; break ; case 'NAME' : $ tags = [ 'FONE' , 'ROMN' , '_HEB' , '_AKA' , '_MARNM' , ] ; break ; default : $ tags = [ ] ; break ; } $ facts = [ ] ; foreach ( $ tags as $ tag ) { $ facts [ $ tag ] = self :: getLabel ( $ tag , null ) ; } uasort ( $ facts , '\Fisharebest\Webtrees\I18N::strcasecmp' ) ; return $ facts ; }
Get a list of facts for use in the fact picker edit control
7,101
public static function createUid ( ) : string { $ uid = str_replace ( '-' , '' , Uuid :: uuid4 ( ) -> toString ( ) ) ; $ checksum_a = 0 ; $ checksum_b = 0 ; for ( $ i = 0 ; $ i < 32 ; $ i += 2 ) { $ checksum_a += hexdec ( substr ( $ uid , $ i , 2 ) ) ; $ checksum_b += $ checksum_a & 0xff ; } return strtoupper ( $ uid . substr ( dechex ( $ checksum_a ) , - 2 ) . substr ( dechex ( $ checksum_b ) , - 2 ) ) ; }
Generate a value for a new _UID field . Instead of RFC4122 - compatible UUIDs generate ones that are compatible with PAF Legacy RootsMagic etc . In these the string is upper - cased dashes are removed and a two - byte checksum is added .
7,102
public function controlPanelManager ( ModuleService $ module_service ) : ResponseInterface { $ all_trees = array_filter ( Tree :: getAll ( ) , static function ( Tree $ tree ) : bool { return Auth :: isManager ( $ tree ) ; } ) ; return $ this -> viewResponse ( 'admin/control-panel-manager' , [ 'title' => I18N :: translate ( 'Control panel' ) , 'all_trees' => $ all_trees , 'changes' => $ this -> totalChanges ( ) , 'individuals' => $ this -> totalIndividuals ( ) , 'families' => $ this -> totalFamilies ( ) , 'sources' => $ this -> totalSources ( ) , 'media' => $ this -> totalMediaObjects ( ) , 'repositories' => $ this -> totalRepositories ( ) , 'notes' => $ this -> totalNotes ( ) , 'individual_list_module' => $ module_service -> findByInterface ( IndividualListModule :: class ) -> first ( ) , 'family_list_module' => $ module_service -> findByInterface ( FamilyListModule :: class ) -> first ( ) , 'media_list_module' => $ module_service -> findByInterface ( MediaListModule :: class ) -> first ( ) , 'note_list_module' => $ module_service -> findByInterface ( NoteListModule :: class ) -> first ( ) , 'repository_list_module' => $ module_service -> findByInterface ( RepositoryListModule :: class ) -> first ( ) , 'source_list_module' => $ module_service -> findByInterface ( SourceListModule :: class ) -> first ( ) , ] ) ; }
Managers see a restricted version of the contol panel .
7,103
private function totalChanges ( ) : array { return DB :: table ( 'gedcom' ) -> leftJoin ( 'change' , static function ( JoinClause $ join ) : void { $ join -> on ( 'change.gedcom_id' , '=' , 'gedcom.gedcom_id' ) -> where ( 'change.status' , '=' , 'pending' ) ; } ) -> groupBy ( 'gedcom.gedcom_id' ) -> pluck ( DB :: raw ( 'COUNT(change_id)' ) , 'gedcom.gedcom_id' ) -> all ( ) ; }
Count the number of pending changes in each tree .
7,104
private function totalFamilies ( ) : Collection { return DB :: table ( 'gedcom' ) -> leftJoin ( 'families' , 'f_file' , '=' , 'gedcom_id' ) -> groupBy ( 'gedcom_id' ) -> pluck ( DB :: raw ( 'COUNT(f_id)' ) , 'gedcom_id' ) -> map ( static function ( string $ count ) { return ( int ) $ count ; } ) ; }
Count the number of families in each tree .
7,105
private function totalNotes ( ) : Collection { return DB :: table ( 'gedcom' ) -> leftJoin ( 'other' , static function ( JoinClause $ join ) : void { $ join -> on ( 'o_file' , '=' , 'gedcom_id' ) -> where ( 'o_type' , '=' , 'NOTE' ) ; } ) -> groupBy ( 'gedcom_id' ) -> pluck ( DB :: raw ( 'COUNT(o_id)' ) , 'gedcom_id' ) -> map ( static function ( string $ count ) { return ( int ) $ count ; } ) ; }
Count the number of notes in each tree .
7,106
protected function nameAtCensusDate ( Individual $ individual , Date $ census_date ) : array { $ names = $ individual -> getAllNames ( ) ; $ name = $ names [ 0 ] ; foreach ( $ individual -> spouseFamilies ( ) as $ family ) { foreach ( $ family -> facts ( [ 'MARR' ] ) as $ marriage ) { if ( $ marriage -> date ( ) -> isOK ( ) && Date :: compare ( $ marriage -> date ( ) , $ census_date ) < 0 ) { $ spouse = $ family -> spouse ( $ individual ) ; foreach ( $ names as $ individual_name ) { foreach ( $ spouse -> getAllNames ( ) as $ spouse_name ) { if ( $ individual_name [ 'type' ] === '_MARNM' && $ individual_name [ 'surn' ] === $ spouse_name [ 'surn' ] ) { return $ individual_name ; } } } } } } return $ name ; }
What was an individual s likely name on a given date allowing for marriages and married names .
7,107
public static function create ( $ name ) : SurnameTraditionInterface { switch ( $ name ) { case 'paternal' : return new PaternalSurnameTradition ( ) ; case 'patrilineal' : return new PatrilinealSurnameTradition ( ) ; case 'matrilineal' : return new MatrilinealSurnameTradition ( ) ; case 'portuguese' : return new PortugueseSurnameTradition ( ) ; case 'spanish' : return new SpanishSurnameTradition ( ) ; case 'polish' : return new PolishSurnameTradition ( ) ; case 'lithuanian' : return new LithuanianSurnameTradition ( ) ; case 'icelandic' : return new IcelandicSurnameTradition ( ) ; default : return new DefaultSurnameTradition ( ) ; } }
Create a surname tradition object for a given surname tradition name .
7,108
public static function addConfigurationLog ( $ message , Tree $ tree = null ) : void { self :: addLog ( $ message , self :: TYPE_CONFIGURATION , $ tree ) ; }
Store a configuration message in the message log .
7,109
public static function addEditLog ( $ message , Tree $ tree ) : void { self :: addLog ( $ message , self :: TYPE_EDIT , $ tree ) ; }
Store an edit message in the message log .
7,110
public static function addSearchLog ( $ message , array $ trees ) : void { foreach ( $ trees as $ tree ) { self :: addLog ( $ message , self :: TYPE_SEARCH , $ tree ) ; } }
Store a search event in the message log . Unlike most webtrees activity search is not restricted to a single tree so we need to record which trees were searchecd .
7,111
final protected function getBlockSetting ( int $ block_id , string $ setting_name , string $ default = '' ) : string { $ settings = app ( 'cache.array' ) -> rememberForever ( 'block_setting' . $ block_id , static function ( ) use ( $ block_id ) : array { return DB :: table ( 'block_setting' ) -> where ( 'block_id' , '=' , $ block_id ) -> pluck ( 'setting_value' , 'setting_name' ) -> all ( ) ; } ) ; return $ settings [ $ setting_name ] ?? $ default ; }
Get a block setting .
7,112
final protected function setBlockSetting ( int $ block_id , string $ setting_name , string $ setting_value ) : self { DB :: table ( 'block_setting' ) -> updateOrInsert ( [ 'block_id' => $ block_id , 'setting_name' => $ setting_name , ] , [ 'setting_value' => $ setting_value , ] ) ; return $ this ; }
Set a block setting .
7,113
final public function getPreference ( string $ setting_name , string $ default = '' ) : string { return DB :: table ( 'module_setting' ) -> where ( 'module_name' , '=' , $ this -> name ( ) ) -> where ( 'setting_name' , '=' , $ setting_name ) -> value ( 'setting_value' ) ?? $ default ; }
Get a module setting . Return a default if the setting is not set .
7,114
final public function setPreference ( string $ setting_name , string $ setting_value ) : void { DB :: table ( 'module_setting' ) -> updateOrInsert ( [ 'module_name' => $ this -> name ( ) , 'setting_name' => $ setting_name , ] , [ 'setting_value' => $ setting_value , ] ) ; }
Set a module setting .
7,115
final public function accessLevel ( Tree $ tree , string $ interface ) : int { $ access_levels = app ( 'cache.array' ) -> rememberForever ( 'module_privacy' . $ tree -> id ( ) , static function ( ) use ( $ tree ) : Collection { return DB :: table ( 'module_privacy' ) -> where ( 'gedcom_id' , '=' , $ tree -> id ( ) ) -> get ( ) ; } ) ; $ row = $ access_levels -> first ( function ( stdClass $ row ) use ( $ interface ) : bool { return $ row -> interface === $ interface && $ row -> module_name === $ this -> name ( ) ; } ) ; return $ row ? ( int ) $ row -> access_level : $ this -> access_level ; }
Get a the current access level for a module
7,116
public function show ( ServerRequestInterface $ request , Tree $ tree , ClipboardService $ clipboard_service ) : ResponseInterface { $ xref = $ request -> get ( 'xref' , '' ) ; $ family = Family :: getInstance ( $ xref , $ tree ) ; Auth :: checkFamilyAccess ( $ family , false ) ; $ clipboard_facts = $ clipboard_service -> pastableFacts ( $ family , new Collection ( ) ) ; return $ this -> viewResponse ( 'family-page' , [ 'facts' => $ family -> facts ( [ ] , true ) , 'meta_robots' => 'index,follow' , 'clipboard_facts' => $ clipboard_facts , 'record' => $ family , 'significant' => $ this -> significant ( $ family ) , 'title' => $ family -> fullName ( ) , ] ) ; }
Show a family s page .
7,117
public static function fileUploadErrorText ( $ error_code ) : string { switch ( $ error_code ) { case UPLOAD_ERR_OK : return I18N :: translate ( 'File successfully uploaded' ) ; case UPLOAD_ERR_INI_SIZE : case UPLOAD_ERR_FORM_SIZE : return I18N :: translate ( 'The uploaded file exceeds the allowed size.' ) ; case UPLOAD_ERR_PARTIAL : return I18N :: translate ( 'The file was only partially uploaded. Please try again.' ) ; case UPLOAD_ERR_NO_FILE : return I18N :: translate ( 'No file was received. Please try again.' ) ; case UPLOAD_ERR_NO_TMP_DIR : return I18N :: translate ( 'The PHP temporary folder is missing.' ) ; case UPLOAD_ERR_CANT_WRITE : return I18N :: translate ( 'PHP failed to write to disk.' ) ; case UPLOAD_ERR_EXTENSION : return I18N :: translate ( 'PHP blocked the file because of its extension.' ) ; default : return 'Error: ' . $ error_code ; } }
Convert a file upload PHP error code into user - friendly text .
7,118
public static function getSubRecord ( $ level , $ tag , $ gedrec , $ num = 1 ) : string { if ( empty ( $ gedrec ) ) { return '' ; } $ gedrec = "\n" . $ gedrec . "\n" ; $ tag = trim ( $ tag ) ; $ searchTarget = "~[\n]" . $ tag . "[\s]~" ; $ ct = preg_match_all ( $ searchTarget , $ gedrec , $ match , PREG_SET_ORDER | PREG_OFFSET_CAPTURE ) ; if ( $ ct === 0 ) { return '' ; } if ( $ ct < $ num ) { return '' ; } $ pos1 = $ match [ $ num - 1 ] [ 0 ] [ 1 ] ; $ pos2 = strpos ( $ gedrec , "\n$level" , $ pos1 + 1 ) ; if ( ! $ pos2 ) { $ pos2 = strpos ( $ gedrec , "\n1" , $ pos1 + 1 ) ; } if ( ! $ pos2 ) { $ pos2 = strpos ( $ gedrec , "\nWT_" , $ pos1 + 1 ) ; } if ( ! $ pos2 ) { return ltrim ( substr ( $ gedrec , $ pos1 ) ) ; } $ subrec = substr ( $ gedrec , $ pos1 , $ pos2 - $ pos1 ) ; return ltrim ( $ subrec ) ; }
get a gedcom subrecord
7,119
public static function getCont ( $ nlevel , $ nrec ) : string { $ text = '' ; $ subrecords = explode ( "\n" , $ nrec ) ; foreach ( $ subrecords as $ thisSubrecord ) { if ( substr ( $ thisSubrecord , 0 , 2 ) !== $ nlevel . ' ' ) { continue ; } $ subrecordType = substr ( $ thisSubrecord , 2 , 4 ) ; if ( $ subrecordType === 'CONT' ) { $ text .= "\n" . substr ( $ thisSubrecord , 7 ) ; } } return $ text ; }
get CONT lines
7,120
public static function getCloseRelationshipName ( Individual $ individual1 , Individual $ individual2 ) : string { if ( $ individual1 === $ individual2 ) { return self :: reflexivePronoun ( $ individual1 ) ; } try { $ relationship = self :: getRelationship ( $ individual1 , $ individual2 ) ; return self :: getRelationshipName ( $ relationship ) ; } catch ( Exception $ ex ) { return '' ; } }
For close family relationships such as the families tab and the family navigator Display a tick if both individuals are the same .
7,121
private static function reflexivePronoun ( Individual $ individual ) : string { switch ( $ individual -> sex ( ) ) { case 'M' : return I18N :: translate ( 'himself' ) ; case 'F' : return I18N :: translate ( 'herself' ) ; default : return I18N :: translate ( 'themself' ) ; } }
Generate a reflexive pronoun for an individual
7,122
public function deleteFact ( ServerRequestInterface $ request , Tree $ tree ) : ResponseInterface { $ xref = $ request -> get ( 'xref' , '' ) ; $ fact_id = $ request -> get ( 'fact_id' ) ; $ record = GedcomRecord :: getInstance ( $ xref , $ tree ) ; Auth :: checkRecordAccess ( $ record , true ) ; foreach ( $ record -> facts ( ) as $ fact ) { if ( $ fact -> id ( ) == $ fact_id && $ fact -> canShow ( ) && $ fact -> canEdit ( ) ) { $ record -> deleteFact ( $ fact_id , true ) ; break ; } } return response ( ) ; }
Delete a fact .
7,123
public function pasteFact ( ServerRequestInterface $ request , Tree $ tree , ClipboardService $ clipboard_service ) : ResponseInterface { $ xref = $ request -> get ( 'xref' , '' ) ; $ fact_id = $ request -> get ( 'fact_id' ) ; $ record = GedcomRecord :: getInstance ( $ xref , $ tree ) ; Auth :: checkRecordAccess ( $ record , true ) ; $ clipboard_service -> pasteFact ( $ fact_id , $ record ) ; return response ( ) ; }
Paste a fact from the clipboard into a record .
7,124
private function totalMediaTypeQuery ( string $ type ) : int { if ( ( $ type !== self :: MEDIA_TYPE_ALL ) && ( $ type !== self :: MEDIA_TYPE_UNKNOWN ) && ! in_array ( $ type , self :: MEDIA_TYPES , true ) ) { return 0 ; } $ query = DB :: table ( 'media' ) -> where ( 'm_file' , '=' , $ this -> tree -> id ( ) ) ; if ( $ type !== self :: MEDIA_TYPE_ALL ) { if ( $ type === self :: MEDIA_TYPE_UNKNOWN ) { foreach ( self :: MEDIA_TYPES as $ t ) { $ query -> where ( static function ( Builder $ query ) use ( $ t ) : void { $ query -> where ( 'm_gedcom' , 'not like' , '%3 TYPE ' . $ t . '%' ) -> where ( 'm_gedcom' , 'not like' , '%1 _TYPE ' . $ t . '%' ) ; } ) ; } } else { $ query -> where ( static function ( Builder $ query ) use ( $ type ) : void { $ query -> where ( 'm_gedcom' , 'like' , '%3 TYPE ' . $ type . '%' ) -> orWhere ( 'm_gedcom' , 'like' , '%1 _TYPE ' . $ type . '%' ) ; } ) ; } } return $ query -> count ( ) ; }
Returns the number of media records of the given type .
7,125
private function getSortedMediaTypeList ( int $ tot ) : array { $ media = [ ] ; $ c = 0 ; $ max = 0 ; foreach ( self :: MEDIA_TYPES as $ type ) { $ count = $ this -> totalMediaTypeQuery ( $ type ) ; if ( $ count > 0 ) { $ media [ $ type ] = $ count ; if ( $ count > $ max ) { $ max = $ count ; } $ c += $ count ; } } $ count = $ this -> totalMediaTypeQuery ( self :: MEDIA_TYPE_UNKNOWN ) ; if ( $ count > 0 ) { $ media [ self :: MEDIA_TYPE_UNKNOWN ] = $ tot - $ c ; if ( $ tot - $ c > $ max ) { $ max = $ count ; } } if ( count ( $ media ) > 10 && ( $ max / $ tot ) > 0.6 ) { arsort ( $ media ) ; $ media = array_slice ( $ media , 0 , 10 ) ; $ c = $ tot ; foreach ( $ media as $ cm ) { $ c -= $ cm ; } if ( isset ( $ media [ self :: MEDIA_TYPE_OTHER ] ) ) { $ media [ self :: MEDIA_TYPE_OTHER ] += $ c ; } else { $ media [ self :: MEDIA_TYPE_OTHER ] = $ c ; } } asort ( $ media ) ; return $ media ; }
Returns a sorted list of media types and their total counts .
7,126
private function formatSexRecord ( Fact $ fact ) : string { $ individual = $ fact -> record ( ) ; switch ( $ fact -> value ( ) ) { case 'M' : $ sex = I18N :: translate ( 'Male' ) ; break ; case 'F' : $ sex = I18N :: translate ( 'Female' ) ; break ; default : $ sex = I18N :: translateContext ( 'unknown gender' , 'Unknown' ) ; break ; } $ container_class = 'card' ; if ( $ fact -> isPendingDeletion ( ) ) { $ container_class .= ' old' ; } elseif ( $ fact -> isPendingAddition ( ) ) { $ container_class .= ' new' ; } if ( $ individual -> canEdit ( ) ) { $ edit_links = '<a class="btn btn-link" href="' . e ( route ( 'edit-fact' , [ 'xref' => $ individual -> xref ( ) , 'fact_id' => $ fact -> id ( ) , 'ged' => $ individual -> tree ( ) -> name ( ) ] ) ) . '" title="' . I18N :: translate ( 'Edit the gender' ) . '">' . view ( 'icons/edit' ) . '<span class="sr-only">' . I18N :: translate ( 'Edit the gender' ) . '</span></a>' ; } else { $ edit_links = '' ; } return ' <div class="' . $ container_class . '"> <div class="card-header" role="tab" id="name-header-add"> <div class="card-title mb-0"> <b>' . I18N :: translate ( 'Gender' ) . '</b> ' . $ sex . $ edit_links . ' </div> </div> </div>' ; }
print information for a sex record
7,127
public function getWidth ( $ renderer ) { if ( $ renderer -> getCurrentStyle ( ) != $ this -> styleName ) { $ renderer -> setCurrentStyle ( $ this -> styleName ) ; } $ fsize = $ renderer -> getCurrentStyleHeight ( ) ; if ( $ fsize > $ renderer -> largestFontHeight ) { $ renderer -> largestFontHeight = $ fsize ; } $ lw = $ renderer -> getStringWidth ( $ this -> text ) ; $ lfct = $ renderer -> countLines ( $ this -> text ) ; $ wrapWidthRemaining = $ this -> wrapWidthRemaining ; if ( $ wrapWidthRemaining > 0 ) { if ( $ lw >= $ wrapWidthRemaining || $ lfct > 1 ) { $ newtext = '' ; $ lines = explode ( "\n" , $ this -> text ) ; foreach ( $ lines as $ line ) { $ lw = $ renderer -> getStringWidth ( $ line ) ; if ( $ lw > $ wrapWidthRemaining ) { $ words = explode ( ' ' , $ line ) ; $ addspace = count ( $ words ) ; $ lw = 0 ; foreach ( $ words as $ word ) { $ addspace -- ; $ lw += $ renderer -> getStringWidth ( $ word . ' ' ) ; if ( $ lw <= $ wrapWidthRemaining ) { $ newtext .= $ word ; if ( $ addspace != 0 ) { $ newtext .= ' ' ; } } else { $ lw = $ renderer -> getStringWidth ( $ word . ' ' ) ; $ newtext .= "\n$word" ; if ( $ addspace != 0 ) { $ newtext .= ' ' ; } $ wrapWidthRemaining = $ this -> wrapWidthCell ; } } } else { $ newtext .= $ line ; } if ( $ lfct > 1 ) { $ newtext .= "\n" ; $ lw = 0 ; $ wrapWidthRemaining = $ this -> wrapWidthCell ; } $ lfct -- ; } $ this -> text = $ newtext ; $ lfct = substr_count ( $ this -> text , "\n" ) ; return [ $ lw , 1 , $ lfct , ] ; } } $ l = 0 ; $ lfct = substr_count ( $ this -> text , "\n" ) ; if ( $ lfct > 0 ) { $ l = 2 ; } return [ $ lw , $ l , $ lfct , ] ; }
Get the width of text and wrap it too
7,128
public function isTimeNearlyUp ( float $ threshold = self :: TIME_UP_THRESHOLD ) : bool { $ max_execution_time = ( int ) ini_get ( 'max_execution_time' ) ; if ( $ max_execution_time === 0 ) { return false ; } $ now = microtime ( true ) ; return $ now + $ threshold > $ this -> start_time + ( float ) $ max_execution_time ; }
Some long - running scripts need to know when to stop .
7,129
public function isTimeLimitUp ( float $ limit = self :: TIME_LIMIT ) : bool { $ now = microtime ( true ) ; return $ now > $ this -> start_time + $ limit ; }
Some long running scripts are broken down into small chunks .
7,130
public static function activeLocales ( ) : array { $ locales = app ( ModuleService :: class ) -> findByInterface ( ModuleLanguageInterface :: class , false , true ) -> map ( static function ( ModuleLanguageInterface $ module ) : LocaleInterface { return $ module -> locale ( ) ; } ) ; if ( $ locales -> isEmpty ( ) ) { return [ new LocaleEnUs ( ) ] ; } return $ locales -> all ( ) ; }
The preferred locales for this site or a default list if no preference .
7,131
public static function installedLocales ( ) : Collection { return app ( ModuleService :: class ) -> findByInterface ( ModuleLanguageInterface :: class , true ) -> map ( static function ( ModuleLanguageInterface $ module ) : LocaleInterface { return $ module -> locale ( ) ; } ) ; }
All locales for which a translation file exists .
7,132
public static function strcasecmp ( $ string1 , $ string2 ) : int { if ( self :: $ collator instanceof Collator ) { return self :: $ collator -> compare ( $ string1 , $ string2 ) ; } return strcmp ( self :: strtolower ( $ string1 ) , self :: strtolower ( $ string2 ) ) ; }
Perform a case - insensitive comparison of two strings .
7,133
public static function strtolower ( $ string ) : string { if ( in_array ( self :: $ locale -> language ( ) -> code ( ) , self :: DOTLESS_I_LOCALES , true ) ) { $ string = strtr ( $ string , self :: DOTLESS_I_TOLOWER ) ; } return mb_strtolower ( $ string ) ; }
Convert a string to lower case .
7,134
public static function strtoupper ( $ string ) : string { if ( in_array ( self :: $ locale -> language ( ) -> code ( ) , self :: DOTLESS_I_LOCALES , true ) ) { $ string = strtr ( $ string , self :: DOTLESS_I_TOUPPER ) ; } return mb_strtoupper ( $ string ) ; }
Convert a string to upper case .
7,135
public static function textScript ( $ string ) : string { $ string = strip_tags ( $ string ) ; $ string = html_entity_decode ( $ string , ENT_QUOTES , 'UTF-8' ) ; $ string = str_replace ( [ '@N.N.' , '@P.N.' , ] , '' , $ string ) ; $ pos = 0 ; $ strlen = strlen ( $ string ) ; while ( $ pos < $ strlen ) { $ byte1 = ord ( $ string [ $ pos ] ) ; if ( $ byte1 < 0x80 ) { $ code_point = $ byte1 ; $ chrlen = 1 ; } elseif ( $ byte1 < 0xC0 ) { return 'Latn' ; } elseif ( $ byte1 < 0xE0 ) { $ code_point = ( ( $ byte1 & 0x1F ) << 6 ) + ( ord ( $ string [ $ pos + 1 ] ) & 0x3F ) ; $ chrlen = 2 ; } elseif ( $ byte1 < 0xF0 ) { $ code_point = ( ( $ byte1 & 0x0F ) << 12 ) + ( ( ord ( $ string [ $ pos + 1 ] ) & 0x3F ) << 6 ) + ( ord ( $ string [ $ pos + 2 ] ) & 0x3F ) ; $ chrlen = 3 ; } elseif ( $ byte1 < 0xF8 ) { $ code_point = ( ( $ byte1 & 0x07 ) << 24 ) + ( ( ord ( $ string [ $ pos + 1 ] ) & 0x3F ) << 12 ) + ( ( ord ( $ string [ $ pos + 2 ] ) & 0x3F ) << 6 ) + ( ord ( $ string [ $ pos + 3 ] ) & 0x3F ) ; $ chrlen = 3 ; } else { return 'Latn' ; } foreach ( self :: SCRIPT_CHARACTER_RANGES as $ range ) { if ( $ code_point >= $ range [ 1 ] && $ code_point <= $ range [ 2 ] ) { return $ range [ 0 ] ; } } $ pos += $ chrlen ; } return 'Latn' ; }
Identify the script used for a piece of text
7,136
public function find ( $ user_id ) : ? User { return app ( 'cache.array' ) -> rememberForever ( __CLASS__ . $ user_id , static function ( ) use ( $ user_id ) : ? User { return DB :: table ( 'user' ) -> where ( 'user_id' , '=' , $ user_id ) -> get ( ) -> map ( User :: rowMapper ( ) ) -> first ( ) ; } ) ; }
Find the user with a specified user_id .
7,137
public function findByEmail ( $ email ) : ? User { return DB :: table ( 'user' ) -> where ( 'email' , '=' , $ email ) -> get ( ) -> map ( User :: rowMapper ( ) ) -> first ( ) ; }
Find the user with a specified email address .
7,138
public function findByIdentifier ( $ identifier ) : ? User { return DB :: table ( 'user' ) -> where ( 'user_name' , '=' , $ identifier ) -> orWhere ( 'email' , '=' , $ identifier ) -> get ( ) -> map ( User :: rowMapper ( ) ) -> first ( ) ; }
Find the user with a specified user_name or email address .
7,139
public function findByUserName ( $ user_name ) : ? User { return DB :: table ( 'user' ) -> where ( 'user_name' , '=' , $ user_name ) -> get ( ) -> map ( User :: rowMapper ( ) ) -> first ( ) ; }
Find the user with a specified user_name .
7,140
public function administrators ( ) : Collection { return DB :: table ( 'user' ) -> join ( 'user_setting' , static function ( JoinClause $ join ) : void { $ join -> on ( 'user_setting.user_id' , '=' , 'user.user_id' ) -> where ( 'user_setting.setting_name' , '=' , 'canadmin' ) -> where ( 'user_setting.setting_value' , '=' , '1' ) ; } ) -> where ( 'user.user_id' , '>' , 0 ) -> orderBy ( 'real_name' ) -> select ( [ 'user.*' ] ) -> get ( ) -> map ( User :: rowMapper ( ) ) ; }
Get a list of all administrators .
7,141
public function allLoggedIn ( ) : Collection { return DB :: table ( 'user' ) -> join ( 'session' , 'session.user_id' , '=' , 'user.user_id' ) -> where ( 'user.user_id' , '>' , 0 ) -> orderBy ( 'real_name' ) -> select ( [ 'user.*' ] ) -> distinct ( ) -> get ( ) -> map ( User :: rowMapper ( ) ) ; }
Get a list of all users who are currently logged in .
7,142
public function create ( string $ user_name , string $ real_name , string $ email , string $ password ) : User { DB :: table ( 'user' ) -> insert ( [ 'user_name' => $ user_name , 'real_name' => $ real_name , 'email' => $ email , 'password' => password_hash ( $ password , PASSWORD_DEFAULT ) , ] ) ; $ user_id = ( int ) DB :: connection ( ) -> getPdo ( ) -> lastInsertId ( ) ; return new User ( $ user_id , $ user_name , $ real_name , $ email ) ; }
Create a new user . The calling code needs to check for duplicates identifiers before calling this function .
7,143
public function statsPlaces ( string $ what = 'ALL' , string $ fact = '' , int $ parent = 0 , bool $ country = false ) : array { if ( $ fact ) { return $ this -> queryFactPlaces ( $ fact , $ what , $ country ) ; } $ query = DB :: table ( 'places' ) -> join ( 'placelinks' , static function ( JoinClause $ join ) : void { $ join -> on ( 'pl_file' , '=' , 'p_file' ) -> on ( 'pl_p_id' , '=' , 'p_id' ) ; } ) -> where ( 'p_file' , '=' , $ this -> tree -> id ( ) ) ; if ( $ parent > 0 ) { $ query -> select ( [ 'p_place AS place' ] ) -> selectRaw ( 'COUNT(*) AS tot' ) -> where ( 'p_id' , '=' , $ parent ) -> groupBy ( [ 'place' ] ) ; } else { $ query -> select ( [ 'p_place AS country' ] ) -> selectRaw ( 'COUNT(*) AS tot' ) -> where ( 'p_parent_id' , '=' , 0 ) -> groupBy ( [ 'country' ] ) -> orderByDesc ( 'tot' ) -> orderBy ( 'country' ) ; } if ( $ what === 'INDI' ) { $ query -> join ( 'individuals' , static function ( JoinClause $ join ) : void { $ join -> on ( 'pl_file' , '=' , 'i_file' ) -> on ( 'pl_gid' , '=' , 'i_id' ) ; } ) ; } elseif ( $ what === 'FAM' ) { $ query -> join ( 'families' , static function ( JoinClause $ join ) : void { $ join -> on ( 'pl_file' , '=' , 'f_file' ) -> on ( 'pl_gid' , '=' , 'f_id' ) ; } ) ; } return $ query -> get ( ) -> all ( ) ; }
Query places .
7,144
private function getTop10Places ( array $ places ) : array { $ top10 = [ ] ; $ i = 0 ; arsort ( $ places ) ; foreach ( $ places as $ place => $ count ) { $ tmp = new Place ( $ place , $ this -> tree ) ; $ top10 [ ] = [ 'place' => $ tmp , 'count' => $ count , ] ; ++ $ i ; if ( $ i === 10 ) { break ; } } return $ top10 ; }
Get the top 10 places list .
7,145
public function commonCountriesList ( ) : string { $ countries = $ this -> statsPlaces ( ) ; if ( empty ( $ countries ) ) { return '' ; } $ top10 = [ ] ; $ i = 1 ; $ country_names = [ ] ; foreach ( I18N :: activeLocales ( ) as $ locale ) { I18N :: init ( $ locale -> languageTag ( ) ) ; $ all_countries = $ this -> country_service -> getAllCountries ( ) ; foreach ( $ all_countries as $ country_code => $ country_name ) { $ country_names [ $ country_name ] = $ country_code ; } } I18N :: init ( WT_LOCALE ) ; $ all_db_countries = [ ] ; foreach ( $ countries as $ place ) { $ country = trim ( $ place -> country ) ; if ( array_key_exists ( $ country , $ country_names ) ) { if ( isset ( $ all_db_countries [ $ country_names [ $ country ] ] [ $ country ] ) ) { $ all_db_countries [ $ country_names [ $ country ] ] [ $ country ] += ( int ) $ place -> tot ; } else { $ all_db_countries [ $ country_names [ $ country ] ] [ $ country ] = ( int ) $ place -> tot ; } } } $ all_countries = $ this -> country_service -> getAllCountries ( ) ; foreach ( $ all_db_countries as $ country_code => $ country ) { foreach ( $ country as $ country_name => $ tot ) { $ tmp = new Place ( $ country_name , $ this -> tree ) ; $ top10 [ ] = [ 'place' => $ tmp , 'count' => $ tot , 'name' => $ all_countries [ $ country_code ] , ] ; } if ( $ i ++ === 10 ) { break ; } } return view ( 'statistics/other/top10-list' , [ 'records' => $ top10 , ] ) ; }
A list of common countries .
7,146
public function setup ( ) : void { $ this -> rtl = I18N :: direction ( ) === 'rtl' ; $ this -> rkeywords = '' ; $ this -> generated_by = I18N :: translate ( 'Generated by %s' , Webtrees :: NAME . ' ' . Webtrees :: VERSION ) ; [ $ this -> page_width , $ this -> page_height ] = self :: PAPER_SIZES [ $ this -> page_format ] ?? self :: PAPER_SIZES [ 'A4' ] ; }
Initial Setup Setting up document wide defaults that will be inherited of the report modules As DEFAULT A4 and Portrait will be used if not set
7,147
public function getStyle ( string $ s ) : array { if ( ! isset ( $ this -> styles [ $ s ] ) ) { return current ( $ this -> styles ) ; } return $ this -> styles [ $ s ] ; }
Get a style from the Styles array
7,148
public function process ( ServerRequestInterface $ request , RequestHandlerInterface $ handler ) : ResponseInterface { $ this -> migration_service -> updateSchema ( '\Fisharebest\Webtrees\Schema' , 'WT_SCHEMA_VERSION' , Webtrees :: SCHEMA_VERSION ) ; return $ handler -> handle ( $ request ) ; }
Update the database schema if necessary .
7,149
public function cleanData ( ServerRequestInterface $ request , FilesystemInterface $ filesystem ) : ResponseInterface { $ protected = [ '.htaccess' , '.gitignore' , 'index.php' , 'config.ini.php' , ] ; if ( $ request -> getAttribute ( 'dbtype' ) === 'sqlite' ) { $ protected [ ] = $ request -> getAttribute ( 'dbname' ) . '.sqlite' ; } foreach ( Tree :: getAll ( ) as $ tree ) { $ media_directory = $ tree -> getPreference ( 'MEDIA_DIRECTORY' ) ; [ $ folder ] = explode ( '/' , $ media_directory ) ; $ protected [ ] = $ folder ; } $ entries = array_map ( static function ( array $ content ) { return $ content [ 'path' ] ; } , $ filesystem -> listContents ( ) ) ; return $ this -> viewResponse ( 'admin/clean-data' , [ 'title' => I18N :: translate ( 'Clean up data folder' ) , 'entries' => $ entries , 'protected' => $ protected , ] ) ; }
Show old user files in the data folder .
7,150
public function cleanDataAction ( ServerRequestInterface $ request , FilesystemInterface $ filesystem ) : ResponseInterface { $ to_delete = ( array ) $ request -> get ( 'to_delete' ) ; $ to_delete = array_filter ( $ to_delete ) ; foreach ( $ to_delete as $ path ) { $ metadata = $ filesystem -> getMetadata ( $ path ) ; if ( $ metadata === false ) { continue ; } if ( $ metadata [ 'type' ] === 'dir' ) { try { $ filesystem -> deleteDir ( $ path ) ; FlashMessages :: addMessage ( I18N :: translate ( 'The folder %s has been deleted.' , e ( $ path ) ) , 'success' ) ; } catch ( Exception $ ex ) { FlashMessages :: addMessage ( I18N :: translate ( 'The folder %s could not be deleted.' , e ( $ path ) ) , 'danger' ) ; } } if ( $ metadata [ 'type' ] === 'file' ) { try { $ filesystem -> delete ( $ path ) ; FlashMessages :: addMessage ( I18N :: translate ( 'The file %s has been deleted.' , e ( $ path ) ) , 'success' ) ; } catch ( Exception $ ex ) { FlashMessages :: addMessage ( I18N :: translate ( 'The file %s could not be deleted.' , e ( $ path ) ) , 'danger' ) ; } } } return redirect ( route ( 'admin-clean-data' ) ) ; }
Delete old user files in the data folder .
7,151
private function logsQuery ( ServerRequestInterface $ request ) : Builder { $ from = $ request -> get ( 'from' ) ; $ to = $ request -> get ( 'to' ) ; $ type = $ request -> get ( 'type' , '' ) ; $ text = $ request -> get ( 'text' , '' ) ; $ ip = $ request -> get ( 'ip' , '' ) ; $ username = $ request -> get ( 'username' , '' ) ; $ gedc = $ request -> get ( 'gedc' ) ; $ query = DB :: table ( 'log' ) -> leftJoin ( 'user' , 'user.user_id' , '=' , 'log.user_id' ) -> leftJoin ( 'gedcom' , 'gedcom.gedcom_id' , '=' , 'log.gedcom_id' ) -> select ( [ 'log.*' , DB :: raw ( "COALESCE(user_name, '<none>') AS user_name" ) , DB :: raw ( "COALESCE(gedcom_name, '<none>') AS gedcom_name" ) ] ) ; if ( $ from !== '' ) { $ query -> where ( 'log_time' , '>=' , $ from ) ; } if ( $ to !== '' ) { $ query -> where ( 'log_time' , '<' , Carbon :: make ( $ to ) -> addDay ( ) ) ; } if ( $ type !== '' ) { $ query -> where ( 'log_type' , '=' , $ type ) ; } if ( $ text ) { $ query -> whereContains ( 'log_message' , $ text ) ; } if ( $ ip ) { $ query -> whereContains ( 'ip_address' , $ ip ) ; } if ( $ username ) { $ query -> whereContains ( 'user_name' , $ ip ) ; } if ( $ gedc ) { $ query -> where ( 'gedcom_name' , '=' , $ gedc ) ; } return $ query ; }
Generate a query for filtering the site log .
7,152
public function serverInformation ( ) : ResponseInterface { ob_start ( ) ; phpinfo ( INFO_ALL & ~ INFO_CREDITS & ~ INFO_LICENSE ) ; $ phpinfo = ob_get_clean ( ) ; preg_match ( '%<body>(.*)</body>%s' , $ phpinfo , $ matches ) ; $ phpinfo = $ matches [ 1 ] ; return $ this -> viewResponse ( 'admin/server-information' , [ 'title' => I18N :: translate ( 'Server information' ) , 'phpinfo' => $ phpinfo , ] ) ; }
Show the server information page .
7,153
public function contactLinkTechnical ( User $ user ) : string { return I18N :: translate ( 'For technical support and information contact %s.' , $ this -> user_service -> contactLink ( $ user ) ) ; }
Create contact link for technical support .
7,154
public static function nameComparator ( ) : Closure { return static function ( GedcomRecord $ x , GedcomRecord $ y ) : int { if ( $ x -> canShowName ( ) ) { if ( $ y -> canShowName ( ) ) { return I18N :: strcasecmp ( $ x -> sortName ( ) , $ y -> sortName ( ) ) ; } return - 1 ; } if ( $ y -> canShowName ( ) ) { return 1 ; } return 0 ; } ; }
A closure which will compare records by name .
7,155
public static function lastChangeComparator ( int $ direction = 1 ) : Closure { return static function ( GedcomRecord $ x , GedcomRecord $ y ) use ( $ direction ) : int { return $ direction * ( $ x -> lastChangeTimestamp ( ) <=> $ y -> lastChangeTimestamp ( ) ) ; } ; }
A closure which will compare records by change time .
7,156
private function parseFacts ( ) : void { if ( $ this -> gedcom ) { $ gedcom_facts = preg_split ( '/\n(?=1)/s' , $ this -> gedcom ) ; array_shift ( $ gedcom_facts ) ; } else { $ gedcom_facts = [ ] ; } if ( $ this -> pending ) { $ pending_facts = preg_split ( '/\n(?=1)/s' , $ this -> pending ) ; array_shift ( $ pending_facts ) ; } else { $ pending_facts = [ ] ; } $ this -> facts = [ ] ; foreach ( $ gedcom_facts as $ gedcom_fact ) { $ fact = new Fact ( $ gedcom_fact , $ this , md5 ( $ gedcom_fact ) ) ; if ( $ this -> pending !== null && ! in_array ( $ gedcom_fact , $ pending_facts , true ) ) { $ fact -> setPendingDeletion ( ) ; } $ this -> facts [ ] = $ fact ; } foreach ( $ pending_facts as $ pending_fact ) { if ( ! in_array ( $ pending_fact , $ gedcom_facts , true ) ) { $ fact = new Fact ( $ pending_fact , $ this , md5 ( $ pending_fact ) ) ; $ fact -> setPendingAddition ( ) ; $ this -> facts [ ] = $ fact ; } } }
Split the record into facts
7,157
private function canShowRecord ( int $ access_level ) : bool { if ( ! $ this -> tree -> getPreference ( 'HIDE_LIVE_PEOPLE' ) ) { return true ; } if ( $ this -> xref ( ) === $ this -> tree -> getUserPreference ( Auth :: user ( ) , 'gedcomid' ) && $ access_level === Auth :: accessLevel ( $ this -> tree ) ) { return true ; } if ( strpos ( $ this -> gedcom , "\n1 RESN confidential" ) !== false ) { return Auth :: PRIV_NONE >= $ access_level ; } if ( strpos ( $ this -> gedcom , "\n1 RESN privacy" ) !== false ) { return Auth :: PRIV_USER >= $ access_level ; } if ( strpos ( $ this -> gedcom , "\n1 RESN none" ) !== false ) { return true ; } $ individual_privacy = $ this -> tree -> getIndividualPrivacy ( ) ; if ( isset ( $ individual_privacy [ $ this -> xref ( ) ] ) ) { return $ individual_privacy [ $ this -> xref ( ) ] >= $ access_level ; } if ( Auth :: PRIV_NONE >= $ access_level ) { return true ; } return $ this -> canShowByType ( $ access_level ) ; }
Work out whether this record can be shown to a user with a given access level
7,158
public function canShow ( int $ access_level = null ) : bool { $ access_level = $ access_level ?? Auth :: accessLevel ( $ this -> tree ) ; if ( $ access_level === Auth :: PRIV_HIDE ) { return true ; } $ cache_key = 'canShow' . $ this -> xref . ':' . $ this -> tree -> id ( ) . ':' . $ access_level ; return app ( 'cache.array' ) -> rememberForever ( $ cache_key , function ( ) use ( $ access_level ) { return $ this -> canShowRecord ( $ access_level ) ; } ) ; }
Can the details of this record be shown?
7,159
public function privatizeGedcom ( int $ access_level ) : string { if ( $ access_level === Auth :: PRIV_HIDE ) { return $ this -> gedcom ; } if ( $ this -> canShow ( $ access_level ) ) { [ $ gedrec ] = explode ( "\n" , $ this -> gedcom , 2 ) ; foreach ( $ this -> facts ( [ ] , false , $ access_level ) as $ fact ) { $ gedrec .= "\n" . $ fact -> gedcom ( ) ; } return $ gedrec ; } return $ this -> createPrivateGedcomRecord ( $ access_level ) ; }
Remove private data from the raw gedcom record . Return both the visible and invisible data . We need the invisible data when editing .
7,160
public function alternateName ( ) : ? string { if ( $ this -> canShowName ( ) && $ this -> getPrimaryName ( ) !== $ this -> getSecondaryName ( ) ) { $ all_names = $ this -> getAllNames ( ) ; return $ all_names [ $ this -> getSecondaryName ( ) ] [ 'full' ] ; } return null ; }
Get the full name in an alternative character set
7,161
public function formatList ( ) : string { $ html = '<a href="' . e ( $ this -> url ( ) ) . '" class="list_item">' ; $ html .= '<b>' . $ this -> fullName ( ) . '</b>' ; $ html .= $ this -> formatListDetails ( ) ; $ html .= '</a>' ; return $ html ; }
Format this object for display in a list
7,162
public function linkedRepositories ( string $ link ) : array { $ rows = DB :: table ( 'other' ) -> join ( 'link' , static function ( JoinClause $ join ) : void { $ join -> on ( 'l_file' , '=' , 'o_file' ) -> on ( 'l_from' , '=' , 'o_id' ) ; } ) -> where ( 'o_file' , '=' , $ this -> tree -> id ( ) ) -> where ( 'o_type' , '=' , 'REPO' ) -> where ( 'l_type' , '=' , $ link ) -> where ( 'l_to' , '=' , $ this -> xref ) -> select ( [ 'o_id AS xref' , 'o_gedcom AS gedcom' ] ) -> get ( ) ; $ list = [ ] ; foreach ( $ rows as $ row ) { $ record = Repository :: getInstance ( $ row -> xref , $ this -> tree , $ row -> gedcom ) ; if ( $ record -> canShowName ( ) ) { $ list [ ] = $ record ; } } return $ list ; }
Find repositories linked to this record .
7,163
public function getAllEventPlaces ( array $ events ) : array { $ places = [ ] ; foreach ( $ this -> facts ( $ events ) as $ event ) { if ( preg_match_all ( '/\n(?:2 PLAC|3 (?:ROMN|FONE|_HEB)) +(.+)/' , $ event -> gedcom ( ) , $ ged_places ) ) { foreach ( $ ged_places [ 1 ] as $ ged_place ) { $ places [ ] = new Place ( $ ged_place , $ this -> tree ) ; } } } return $ places ; }
Get all the places for a particular type of event
7,164
public function facts ( array $ filter = [ ] , bool $ sort = false , int $ access_level = null , bool $ override = false ) : Collection { if ( $ access_level === null ) { $ access_level = Auth :: accessLevel ( $ this -> tree ) ; } $ facts = new Collection ( ) ; if ( $ this -> canShow ( $ access_level ) || $ override ) { foreach ( $ this -> facts as $ fact ) { if ( ( $ filter === [ ] || in_array ( $ fact -> getTag ( ) , $ filter , true ) ) && $ fact -> canShow ( $ access_level ) ) { $ facts -> push ( $ fact ) ; } } } if ( $ sort ) { $ facts = Fact :: sortFacts ( $ facts ) ; } return new Collection ( $ facts ) ; }
The facts and events for this record .
7,165
public function lastChangeTimestamp ( ) : Carbon { $ chan = $ this -> facts ( [ 'CHAN' ] ) -> first ( ) ; if ( $ chan instanceof Fact ) { $ d = $ chan -> date ( ) -> minimumDate ( ) ; if ( preg_match ( '/\n3 TIME (\d\d):(\d\d):(\d\d)/' , $ chan -> gedcom ( ) , $ match ) ) { return Carbon :: create ( $ d -> year ( ) , $ d -> month ( ) , $ d -> day ( ) , ( int ) $ match [ 1 ] , ( int ) $ match [ 2 ] , ( int ) $ match [ 3 ] ) ; } if ( preg_match ( '/\n3 TIME (\d\d):(\d\d)/' , $ chan -> gedcom ( ) , $ match ) ) { return Carbon :: create ( $ d -> year ( ) , $ d -> month ( ) , $ d -> day ( ) , ( int ) $ match [ 1 ] , ( int ) $ match [ 2 ] ) ; } return Carbon :: create ( $ d -> year ( ) , $ d -> month ( ) , $ d -> day ( ) ) ; } return Carbon :: createFromTimestamp ( 0 ) ; }
Get the last - change timestamp for this record
7,166
public function lastChangeUser ( ) : string { $ chan = $ this -> facts ( [ 'CHAN' ] ) -> first ( ) ; if ( $ chan === null ) { return I18N :: translate ( 'Unknown' ) ; } $ chan_user = $ chan -> attribute ( '_WT_USER' ) ; if ( $ chan_user === '' ) { return I18N :: translate ( 'Unknown' ) ; } return $ chan_user ; }
Get the last - change user for this record
7,167
public function createFact ( string $ gedcom , bool $ update_chan ) : void { $ this -> updateFact ( '' , $ gedcom , $ update_chan ) ; }
Add a new fact to this record
7,168
public function deleteFact ( string $ fact_id , bool $ update_chan ) : void { $ this -> updateFact ( $ fact_id , '' , $ update_chan ) ; }
Delete a fact from this record
7,169
public function updateFact ( string $ fact_id , string $ gedcom , bool $ update_chan ) : void { $ gedcom = preg_replace ( '/[\r\n]+/' , "\n" , $ gedcom ) ; $ gedcom = trim ( $ gedcom ) ; if ( $ this -> pending === '' ) { throw new Exception ( 'Cannot edit a deleted record' ) ; } if ( $ gedcom !== '' && ! preg_match ( '/^1 ' . Gedcom :: REGEX_TAG . '/' , $ gedcom ) ) { throw new Exception ( 'Invalid GEDCOM data passed to GedcomRecord::updateFact(' . $ gedcom . ')' ) ; } if ( $ this -> pending ) { $ old_gedcom = $ this -> pending ; } else { $ old_gedcom = $ this -> gedcom ; } [ $ new_gedcom ] = explode ( "\n" , $ old_gedcom , 2 ) ; foreach ( $ this -> facts ( [ ] , false , Auth :: PRIV_HIDE ) as $ fact ) { if ( ! $ fact -> isPendingDeletion ( ) ) { if ( $ fact -> id ( ) === $ fact_id ) { if ( $ gedcom !== '' ) { $ new_gedcom .= "\n" . $ gedcom ; } $ fact_id = 'NOT A VALID FACT ID' ; } elseif ( $ fact -> getTag ( ) !== 'CHAN' || ! $ update_chan ) { $ new_gedcom .= "\n" . $ fact -> gedcom ( ) ; } } } if ( $ update_chan ) { $ new_gedcom .= "\n1 CHAN\n2 DATE " . strtoupper ( date ( 'd M Y' ) ) . "\n3 TIME " . date ( 'H:i:s' ) . "\n2 _WT_USER " . Auth :: user ( ) -> userName ( ) ; } if ( $ fact_id === '' ) { $ new_gedcom .= "\n" . $ gedcom ; } if ( $ new_gedcom !== $ old_gedcom ) { DB :: table ( 'change' ) -> insert ( [ 'gedcom_id' => $ this -> tree -> id ( ) , 'xref' => $ this -> xref , 'old_gedcom' => $ old_gedcom , 'new_gedcom' => $ new_gedcom , 'user_id' => Auth :: id ( ) , ] ) ; $ this -> pending = $ new_gedcom ; if ( Auth :: user ( ) -> getPreference ( 'auto_accept' ) ) { FunctionsImport :: acceptAllChanges ( $ this -> xref , $ this -> tree ) ; $ this -> gedcom = $ new_gedcom ; $ this -> pending = null ; } } $ this -> parseFacts ( ) ; }
Replace a fact with a new gedcom data .
7,170
public function updateRecord ( string $ gedcom , bool $ update_chan ) : void { $ gedcom = preg_replace ( '/[\r\n]+/' , "\n" , $ gedcom ) ; $ gedcom = trim ( $ gedcom ) ; if ( $ update_chan ) { $ gedcom = preg_replace ( '/\n1 CHAN(\n[2-9].*)*/' , '' , $ gedcom ) ; $ gedcom .= "\n1 CHAN\n2 DATE " . date ( 'd M Y' ) . "\n3 TIME " . date ( 'H:i:s' ) . "\n2 _WT_USER " . Auth :: user ( ) -> userName ( ) ; } DB :: table ( 'change' ) -> insert ( [ 'gedcom_id' => $ this -> tree -> id ( ) , 'xref' => $ this -> xref , 'old_gedcom' => $ this -> gedcom ( ) , 'new_gedcom' => $ gedcom , 'user_id' => Auth :: id ( ) , ] ) ; $ this -> pending = $ gedcom ; if ( Auth :: user ( ) -> getPreference ( 'auto_accept' ) ) { FunctionsImport :: acceptAllChanges ( $ this -> xref , $ this -> tree ) ; $ this -> gedcom = $ gedcom ; $ this -> pending = null ; } $ this -> parseFacts ( ) ; Log :: addEditLog ( 'Update: ' . static :: RECORD_TYPE . ' ' . $ this -> xref , $ this -> tree ) ; }
Update this record
7,171
public function linkingRecords ( ) : array { $ union = DB :: table ( 'change' ) -> where ( 'gedcom_id' , '=' , $ this -> tree ( ) -> id ( ) ) -> whereContains ( 'new_gedcom' , '@' . $ this -> xref ( ) . '@' ) -> where ( 'new_gedcom' , 'NOT LIKE' , '0 @' . $ this -> xref ( ) . '@%' ) -> select ( [ 'xref' ] ) ; $ xrefs = DB :: table ( 'link' ) -> where ( 'l_file' , '=' , $ this -> tree ( ) -> id ( ) ) -> where ( 'l_to' , '=' , $ this -> xref ( ) ) -> select ( 'l_from' ) -> union ( $ union ) -> pluck ( 'l_from' ) ; return $ xrefs -> map ( function ( string $ xref ) : GedcomRecord { return GedcomRecord :: getInstance ( $ xref , $ this -> tree ) ; } ) -> all ( ) ; }
Fetch XREFs of all records linked to a record - when deleting an object we must also delete all links to it .
7,172
public function chartSex ( int $ tot_m , int $ tot_f , int $ tot_u , string $ color_female = null , string $ color_male = null , string $ color_unknown = null ) : string { $ color_female = $ color_female ?? '#ffd1dc' ; $ color_male = $ color_male ?? '#84beff' ; $ color_unknown = $ color_unknown ?? '#777777' ; $ data = [ [ I18N :: translate ( 'Type' ) , I18N :: translate ( 'Total' ) ] , ] ; if ( $ tot_m || $ tot_f || $ tot_u ) { $ data [ ] = [ I18N :: translate ( 'Males' ) , $ tot_m ] ; $ data [ ] = [ I18N :: translate ( 'Females' ) , $ tot_f ] ; $ data [ ] = [ I18N :: translate ( 'Unknown' ) , $ tot_u ] ; } return view ( 'statistics/other/charts/pie' , [ 'title' => null , 'data' => $ data , 'colors' => [ $ color_male , $ color_female , $ color_unknown ] , 'labeledValueText' => 'percentage' , ] ) ; }
Generate a chart showing sex distribution .
7,173
public function createNoteObjectAction ( ServerRequestInterface $ request , Tree $ tree ) : ResponseInterface { $ note = $ request -> get ( 'note' , '' ) ; $ privacy_restriction = $ request -> get ( 'privacy-restriction' , '' ) ; $ edit_restriction = $ request -> get ( 'edit-restriction' , '' ) ; $ note = preg_replace ( '/\r|\r\n|\n|\r/' , "\n1 CONT " , $ note ) ; $ gedcom = '0 @@ NOTE ' . $ note ; if ( in_array ( $ privacy_restriction , [ 'none' , 'privacy' , 'confidential' , ] ) ) { $ gedcom .= "\n1 RESN " . $ privacy_restriction ; } if ( in_array ( $ edit_restriction , [ 'locked' ] ) ) { $ gedcom .= "\n1 RESN " . $ edit_restriction ; } $ record = $ tree -> createRecord ( $ gedcom ) ; return response ( [ 'id' => $ record -> xref ( ) , 'text' => view ( 'selects/note' , [ 'note' => $ record , ] ) , 'html' => view ( 'modals/record-created' , [ 'title' => I18N :: translate ( 'The note has been created' ) , 'name' => $ record -> fullName ( ) , 'url' => $ record -> url ( ) , ] ) , ] ) ; }
Process a form to create a new note object .
7,174
private function allRecordsInCart ( Tree $ tree ) : array { $ cart = Session :: get ( 'cart' , [ ] ) ; $ xrefs = array_keys ( $ cart [ $ tree -> name ( ) ] ?? [ ] ) ; $ records = array_map ( static function ( string $ xref ) use ( $ tree ) : GedcomRecord { return GedcomRecord :: getInstance ( $ xref , $ tree ) ; } , $ xrefs ) ; $ records = array_filter ( $ records ) ; uasort ( $ records , static function ( GedcomRecord $ x , GedcomRecord $ y ) : int { return $ x :: RECORD_TYPE <=> $ y :: RECORD_TYPE ? : GedcomRecord :: nameComparator ( ) ( $ x , $ y ) ; } ) ; return $ records ; }
Get all the records in the cart .
7,175
private function addRecordToCart ( GedcomRecord $ record ) : void { $ cart = Session :: get ( 'cart' , [ ] ) ; $ tree_name = $ record -> tree ( ) -> name ( ) ; $ cart [ $ tree_name ] [ $ record -> xref ( ) ] = true ; preg_match_all ( '/\n\d (?:OBJE|NOTE|SOUR|REPO) @(' . Gedcom :: REGEX_XREF . ')@/' , $ record -> gedcom ( ) , $ matches ) ; foreach ( $ matches [ 1 ] as $ match ) { $ cart [ $ tree_name ] [ $ match ] = true ; } Session :: put ( 'cart' , $ cart ) ; }
Add a record ( and direclty linked sources notes etc . to the cart .
7,176
private function allAncestors ( $ xref1 , $ xref2 , $ tree_id ) : array { $ ancestors = [ $ xref1 , $ xref2 , ] ; $ queue = [ $ xref1 , $ xref2 , ] ; while ( ! empty ( $ queue ) ) { $ parents = DB :: table ( 'link AS l1' ) -> join ( 'link AS l2' , static function ( JoinClause $ join ) : void { $ join -> on ( 'l1.l_to' , '=' , 'l2.l_to' ) -> on ( 'l1.l_file' , '=' , 'l2.l_file' ) ; } ) -> where ( 'l1.l_file' , '=' , $ tree_id ) -> where ( 'l1.l_type' , '=' , 'FAMC' ) -> where ( 'l2.l_type' , '=' , 'FAMS' ) -> whereIn ( 'l1.l_from' , $ queue ) -> pluck ( 'l2.l_from' ) ; $ queue = [ ] ; foreach ( $ parents as $ parent ) { if ( ! in_array ( $ parent , $ ancestors , true ) ) { $ ancestors [ ] = $ parent ; $ queue [ ] = $ parent ; } } } return $ ancestors ; }
Find all ancestors of a list of individuals
7,177
private function excludeFamilies ( $ xref1 , $ xref2 , $ tree_id ) : array { return DB :: table ( 'link AS l1' ) -> join ( 'link AS l2' , static function ( JoinClause $ join ) : void { $ join -> on ( 'l1.l_to' , '=' , 'l2.l_to' ) -> on ( 'l1.l_type' , '=' , 'l2.l_type' ) -> on ( 'l1.l_file' , '=' , 'l2.l_file' ) ; } ) -> where ( 'l1.l_file' , '=' , $ tree_id ) -> where ( 'l1.l_type' , '=' , 'FAMS' ) -> where ( 'l1.l_from' , '=' , $ xref1 ) -> where ( 'l2.l_from' , '=' , $ xref2 ) -> pluck ( 'l1.l_to' ) -> all ( ) ; }
Find all families of two individuals
7,178
public function extractWebtreesZip ( string $ zip_file , string $ target_folder ) : void { $ zip = new ZipArchive ( ) ; if ( $ zip -> open ( $ zip_file ) ) { $ zip -> extractTo ( $ target_folder ) ; $ zip -> close ( ) ; } else { throw new InternalServerErrorException ( 'Cannot read ZIP file. Is it corrupt?' ) ; } }
Unpack webtrees . zip .
7,179
public function webtreesZipContents ( string $ zip_file ) : Collection { $ zip_adapter = new ZipArchiveAdapter ( $ zip_file , null , 'webtrees' ) ; $ zip_filesystem = new Filesystem ( new CachedAdapter ( $ zip_adapter , new Memory ( ) ) ) ; $ paths = new Collection ( $ zip_filesystem -> listContents ( '' , true ) ) ; return $ paths -> filter ( static function ( array $ path ) : bool { return $ path [ 'type' ] === 'file' ; } ) -> map ( static function ( array $ path ) : string { return $ path [ 'path' ] ; } ) ; }
Create a list of all the files in a webtrees . ZIP archive
7,180
protected function chart ( Individual $ individual , int $ generations , bool $ show_spouse ) : ResponseInterface { $ this -> layout = 'layouts/ajax' ; return $ this -> viewResponse ( 'modules/hourglass-chart/chart' , [ 'generations' => $ generations , 'individual' => $ individual , 'show_spouse' => $ show_spouse , ] ) ; }
Generate the initial generations of the chart
7,181
public function setup ( ) : void { parent :: setup ( ) ; if ( $ this -> orientation === 'landscape' ) { $ tmpw = $ this -> page_width ; $ this -> page_width = $ this -> page_height ; $ this -> page_height = $ tmpw ; } $ this -> noMarginWidth = $ this -> page_width - $ this -> left_margin - $ this -> right_margin ; if ( $ this -> rtl ) { $ this -> alignRTL = 'right' ; $ this -> entityRTL = '&rlm;' ; } $ this -> default_font = 'Arial' ; if ( $ this -> show_generated_by ) { $ element = new ReportHtmlCell ( 0 , 10 , 0 , 'C' , '' , 'genby' , 1 , ReportBaseElement :: CURRENT_POSITION , ReportBaseElement :: CURRENT_POSITION , 0 , 0 , '' , '' , true ) ; $ element -> addText ( $ this -> generated_by ) ; $ element -> setUrl ( Webtrees :: VERSION ) ; $ this -> footerElements [ ] = $ element ; } }
HTML Setup - ReportHtml
7,182
private function runPageHeader ( ) { foreach ( $ this -> pageHeaderElements as $ element ) { if ( $ element instanceof ReportBaseElement ) { $ element -> render ( $ this ) ; } elseif ( $ element === 'footnotetexts' ) { $ this -> footnotes ( ) ; } elseif ( $ element === 'addpage' ) { $ this -> addPage ( ) ; } } }
Generate the page header
7,183
public function createCell ( $ width , $ height , $ border , $ align , $ bgcolor , $ style , $ ln , $ top , $ left , $ fill , $ stretch , $ bocolor , $ tcolor , $ reseth ) : ReportBaseCell { return new ReportHtmlCell ( $ width , $ height , $ border , $ align , $ bgcolor , $ style , $ ln , $ top , $ left , $ fill , $ stretch , $ bocolor , $ tcolor , $ reseth ) ; }
Create a new Cell object .
7,184
public function createTextBox ( float $ width , float $ height , bool $ border , string $ bgcolor , bool $ newline , float $ left , float $ top , bool $ pagecheck , string $ style , bool $ fill , bool $ padding , bool $ reseth ) : ReportBaseTextbox { return new ReportHtmlTextbox ( $ width , $ height , $ border , $ bgcolor , $ newline , $ left , $ top , $ pagecheck , $ style , $ fill , $ padding , $ reseth ) ; }
Create a new TextBox object .
7,185
public function addPage ( ) { $ this -> pageN ++ ; $ this -> maxY += 10 ; if ( $ this -> maxY < $ this -> Y ) { $ this -> maxY = $ this -> Y ; } else { $ this -> Y = $ this -> maxY ; } }
Update the Page Number and set a new Y if max Y is larger - ReportHtml
7,186
public function checkFootnote ( ReportHtmlFootnote $ footnote ) { $ ct = count ( $ this -> printedfootnotes ) ; $ i = 0 ; $ val = $ footnote -> getValue ( ) ; while ( $ i < $ ct ) { if ( $ this -> printedfootnotes [ $ i ] -> getValue ( ) == $ val ) { $ footnote -> setNum ( $ i + 1 ) ; $ footnote -> setAddlink ( ( string ) ( $ i + 1 ) ) ; return $ this -> printedfootnotes [ $ i ] ; } $ i ++ ; } $ footnote -> setNum ( $ ct + 1 ) ; $ footnote -> setAddlink ( ( string ) ( $ ct + 1 ) ) ; $ this -> printedfootnotes [ ] = $ footnote ; return false ; }
Checks the Footnote and numbers them - ReportHtml
7,187
public function getCurrentStyleHeight ( ) : float { if ( empty ( $ this -> currentStyle ) ) { return $ this -> default_font_size ; } $ style = $ this -> getStyle ( $ this -> currentStyle ) ; return $ style [ 'size' ] ; }
Get the current style height .
7,188
public function getFootnotesHeight ( float $ cellWidth ) : float { $ h = 0 ; foreach ( $ this -> printedfootnotes as $ element ) { $ h += $ element -> getFootnoteHeight ( $ this , $ cellWidth ) ; } return $ h ; }
Get the current footnotes height .
7,189
public function getStringWidth ( string $ text ) : float { $ style = $ this -> getStyle ( $ this -> currentStyle ) ; return mb_strlen ( $ text ) * ( $ style [ 'size' ] / 2 ) ; }
Get the width of a string .
7,190
public function getTextCellHeight ( string $ str ) : float { $ nl = $ this -> countLines ( $ str ) ; return ceil ( ( $ this -> getCurrentStyleHeight ( ) * $ this -> cellHeightRatio ) * $ nl ) ; }
Get a text height in points - ReportHtml
7,191
public function setY ( $ y ) { $ this -> Y = $ y ; if ( $ this -> maxY < $ y ) { $ this -> maxY = $ y ; } }
Set the Y position - ReportHtml
7,192
public function textWrap ( string $ str , float $ width ) : string { $ lw = ( int ) ( $ width / ( $ this -> getCurrentStyleHeight ( ) / 2 ) ) ; $ lines = explode ( "\n" , $ str ) ; $ lfct = count ( $ lines ) ; $ wraptext = '' ; foreach ( $ lines as $ line ) { $ wtext = FunctionsRtl :: utf8WordWrap ( $ line , $ lw , "\n" , true ) ; $ wraptext .= $ wtext ; if ( $ lfct > 1 ) { $ wraptext .= "\n" ; } $ lfct -- ; } return $ wraptext ; }
Wrap text - ReportHtml
7,193
public function write ( $ text , $ color = '' , $ useclass = true ) { $ style = $ this -> getStyle ( $ this -> getCurrentStyle ( ) ) ; $ htmlcode = '<span dir="' . I18N :: direction ( ) . '"' ; if ( $ useclass ) { $ htmlcode .= ' class="' . $ style [ 'name' ] . '"' ; } if ( ! empty ( $ color ) ) { if ( preg_match ( '/#?(..)(..)(..)/' , $ color ) ) { $ htmlcode .= ' style="color:' . $ color . ';"' ; } } $ htmlcode .= '>' . $ text . '</span>' ; $ htmlcode = str_replace ( [ "\n" , '> ' , ' <' , ] , [ '<br>' , '>&nbsp;' , '&nbsp;<' , ] , $ htmlcode ) ; echo $ htmlcode ; }
Write text - ReportHtml
7,194
public function step ( ServerRequestInterface $ request , ? Tree $ tree ) : ResponseInterface { $ step = $ request -> getQueryParams ( ) [ 'step' ] ?? self :: STEP_CHECK ; switch ( $ step ) { case self :: STEP_CHECK : return $ this -> wizardStepCheck ( ) ; case self :: STEP_PREPARE : return $ this -> wizardStepPrepare ( ) ; case self :: STEP_PENDING : return $ this -> wizardStepPending ( ) ; case self :: STEP_EXPORT : if ( $ tree === null ) { throw new RuntimeException ( 'Exporting a non-existant tree?' ) ; } return $ this -> wizardStepExport ( $ tree ) ; case self :: STEP_DOWNLOAD : return $ this -> wizardStepDownload ( ) ; case self :: STEP_UNZIP : return $ this -> wizardStepUnzip ( ) ; case self :: STEP_COPY : return $ this -> wizardStepCopy ( ) ; case self :: STEP_CLEANUP : return $ this -> wizardStepCleanup ( ) ; } throw new NotFoundHttpException ( ) ; }
Perform one step of the wizard
7,195
private function wizardStepPrepare ( ) : ResponseInterface { $ this -> filesystem -> deleteDir ( self :: UPGRADE_FOLDER ) ; $ this -> filesystem -> createDir ( self :: UPGRADE_FOLDER ) ; return response ( view ( 'components/alert-success' , [ 'alert' => I18N :: translate ( 'The folder %s has been created.' , e ( self :: UPGRADE_FOLDER ) ) , ] ) ) ; }
Make sure the temporary folder exists .
7,196
public static function addMessage ( $ text , $ status = 'info' ) : void { $ message = new stdClass ( ) ; $ message -> text = $ text ; $ message -> status = $ status ; $ messages = Session :: get ( self :: FLASH_KEY , [ ] ) ; $ messages [ ] = $ message ; Session :: put ( self :: FLASH_KEY , $ messages ) ; }
Add a message to the session storage .
7,197
public static function getMessages ( ) : array { $ messages = Session :: get ( self :: FLASH_KEY , [ ] ) ; Session :: forget ( self :: FLASH_KEY ) ; return $ messages ; }
Get the current messages and remove them from session storage .
7,198
public function deleteOldWebtreesFiles ( Filesystem $ filesystem ) : array { $ paths_to_delete = [ ] ; foreach ( self :: OLD_PATHS as $ path ) { if ( ! $ this -> deleteFileOrFolder ( $ filesystem , $ path ) ) { $ paths_to_delete [ ] = $ path ; } } return $ paths_to_delete ; }
Delete files and folders that belonged to an earlier version of webtrees . Return a list of those that we could not delete .
7,199
public function deleteOldFiles ( Filesystem $ filesystem , string $ path , int $ max_age ) : void { $ list = $ filesystem -> listContents ( $ path , true ) ; $ timestamp = Carbon :: now ( ) -> unix ( ) ; foreach ( $ list as $ metadata ) { if ( $ metadata [ 'timestamp' ] ?? $ timestamp < $ timestamp - $ max_age ) { $ this -> deleteFileOrFolder ( $ filesystem , $ metadata [ 'path' ] ) ; } } }
Delete old cache files .