idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
7,300
protected function subtitle ( int $ count , Date $ start , Date $ end , string $ placename ) : string { if ( $ start -> isOK ( ) && $ end -> isOK ( ) && $ placename !== '' ) { return I18N :: plural ( '%s individual with events in %s between %s and %s' , '%s individuals with events in %s between %s and %s' , $ count , I18N :: number ( $ count ) , $ placename , $ start -> display ( false , '%Y' ) , $ end -> display ( false , '%Y' ) ) ; } if ( $ placename !== '' ) { return I18N :: plural ( '%s individual with events in %s' , '%s individuals with events in %s' , $ count , I18N :: number ( $ count ) , $ placename ) ; } if ( $ start -> isOK ( ) && $ end -> isOK ( ) ) { return I18N :: plural ( '%s individual with events between %s and %s' , '%s individuals with events between %s and %s' , $ count , I18N :: number ( $ count ) , $ start -> display ( false , '%Y' ) , $ end -> display ( false , '%Y' ) ) ; } return I18N :: plural ( '%s individual' , '%s individuals' , $ count , I18N :: number ( $ count ) ) ; }
Generate a subtitle based on filter parameters
7,301
public function registerPage ( ServerRequestInterface $ request ) : ResponseInterface { $ this -> checkRegistrationAllowed ( ) ; $ comments = $ request -> get ( 'comments' , '' ) ; $ email = $ request -> get ( 'email' , '' ) ; $ realname = $ request -> get ( 'realname' , '' ) ; $ username = $ request -> get ( 'username' , '' ) ; $ show_caution = Site :: getPreference ( 'SHOW_REGISTER_CAUTION' ) === '1' ; $ title = I18N :: translate ( 'Request a new user account' ) ; return $ this -> viewResponse ( 'register-page' , [ 'comments' => $ comments , 'email' => $ email , 'realname' => $ realname , 'show_caution' => $ show_caution , 'title' => $ title , 'username' => $ username , ] ) ; }
Show a registration page .
7,302
public function verifyPage ( ) : ResponseInterface { $ this -> checkRegistrationAllowed ( ) ; $ title = I18N :: translate ( 'User verification' ) ; return $ this -> viewResponse ( 'register-page' , [ 'title' => $ title , ] ) ; }
Show an email verification page .
7,303
public static function templeNames ( ) : array { $ temple_names = [ ] ; foreach ( self :: templeCodes ( ) as $ temple_code ) { $ temple_names [ $ temple_code ] = self :: templeName ( $ temple_code ) ; } uasort ( $ temple_names , '\Fisharebest\Webtrees\I18N::strcasecmp' ) ; return $ temple_names ; }
A sorted list of all temple names
7,304
public function asText ( ) : string { if ( $ this -> keyword === self :: KEYWORD_STILLBORN ) { return I18N :: translate ( '(stillborn)' ) ; } if ( $ this -> keyword === self :: KEYWORD_INFANT ) { return I18N :: translate ( '(in infancy)' ) ; } if ( $ this -> keyword === self :: KEYWORD_CHILD ) { return I18N :: translate ( '(in childhood)' ) ; } $ age = [ ] ; if ( $ this -> years > 0 || $ this -> months === 0 && $ this -> weeks === 0 && $ this -> days === 0 ) { $ age [ ] = I18N :: plural ( '%s year' , '%s years' , $ this -> years , I18N :: number ( $ this -> years ) ) ; } if ( $ this -> months > 0 ) { $ age [ ] = I18N :: plural ( '%s month' , '%s months' , $ this -> months , I18N :: number ( $ this -> months ) ) ; } if ( $ this -> weeks > 0 ) { $ age [ ] = I18N :: plural ( '%s week' , '%s weeks' , $ this -> weeks , I18N :: number ( $ this -> weeks ) ) ; } if ( $ this -> days > 0 ) { $ age [ ] = I18N :: plural ( '%s day' , '%s days' , $ this -> days , I18N :: number ( $ this -> days ) ) ; } if ( $ this -> years > 0 && $ this -> months === 0 && $ this -> weeks === 0 && $ this -> days === 0 ) { $ age = [ I18N :: number ( $ this -> years ) ] ; } $ age_string = implode ( I18N :: $ list_separator , $ age ) ; if ( $ this -> qualifier === self :: SYMBOL_LESS_THAN ) { return I18N :: translate ( '(aged less than %s)' , $ age_string ) ; } if ( $ this -> qualifier === self :: SYMBOL_MORE_THAN ) { return I18N :: translate ( '(aged more than %s)' , $ age_string ) ; } return I18N :: translate ( '(aged %s)' , $ age_string ) ; }
Convert an age to localised text .
7,305
public function render ( $ renderer ) { if ( $ this -> x1 === ReportBaseElement :: CURRENT_POSITION ) { $ this -> x1 = $ renderer -> GetX ( ) ; } if ( $ this -> y1 === ReportBaseElement :: CURRENT_POSITION ) { $ this -> y1 = $ renderer -> GetY ( ) ; } if ( $ this -> x2 === ReportBaseElement :: CURRENT_POSITION ) { $ this -> x2 = $ renderer -> getMaxLineWidth ( ) ; } if ( $ this -> y2 === ReportBaseElement :: CURRENT_POSITION ) { $ this -> y2 = $ renderer -> GetY ( ) ; } if ( $ renderer -> getRTL ( ) ) { $ renderer -> Line ( $ renderer -> getPageWidth ( ) - $ this -> x1 , $ this -> y1 , $ renderer -> getPageWidth ( ) - $ this -> x2 , $ this -> y2 ) ; } else { $ renderer -> Line ( $ this -> x1 , $ this -> y1 , $ this -> x2 , $ this -> y2 ) ; } }
PDF line renderer
7,306
public function render ( $ renderer ) { static $ lastpicbottom , $ lastpicpage , $ lastpicleft , $ lastpicright ; if ( $ renderer -> checkPageBreakPDF ( $ this -> height + 5 ) ) { $ this -> y = $ renderer -> GetY ( ) ; } $ curx = $ renderer -> GetX ( ) ; if ( $ this -> x === ReportBaseElement :: CURRENT_POSITION ) { $ this -> x = $ renderer -> GetX ( ) ; } else { $ this -> x = $ renderer -> addMarginX ( $ this -> x ) ; $ renderer -> SetX ( $ curx ) ; } if ( $ this -> y === ReportBaseElement :: CURRENT_POSITION ) { if ( isset ( $ lastpicbottom ) ) { if ( ( $ renderer -> PageNo ( ) == $ lastpicpage ) && ( $ lastpicbottom >= $ renderer -> GetY ( ) ) && ( $ this -> x >= $ lastpicleft ) && ( $ this -> x <= $ lastpicright ) ) { $ renderer -> SetY ( $ lastpicbottom + 5 ) ; } } $ this -> y = $ renderer -> GetY ( ) ; } else { $ renderer -> SetY ( $ this -> y ) ; } if ( $ renderer -> getRTL ( ) ) { $ renderer -> Image ( $ this -> file , $ renderer -> getPageWidth ( ) - $ this -> x , $ this -> y , $ this -> width , $ this -> height , '' , '' , $ this -> line , false , 72 , $ this -> align ) ; } else { $ renderer -> Image ( $ this -> file , $ this -> x , $ this -> y , $ this -> width , $ this -> height , '' , '' , $ this -> line , false , 72 , $ this -> align ) ; } $ lastpicpage = $ renderer -> PageNo ( ) ; $ renderer -> lastpicpage = $ renderer -> getPage ( ) ; $ lastpicleft = $ this -> x ; $ lastpicright = $ this -> x + $ this -> width ; $ lastpicbottom = $ this -> y + $ this -> height ; if ( $ this -> line === 'N' ) { $ renderer -> SetY ( $ lastpicbottom ) ; } }
PDF image renderer
7,307
public function getPersons ( Tree $ tree , string $ request ) : string { $ json_requests = explode ( ';' , $ request ) ; $ r = [ ] ; foreach ( $ json_requests as $ json_request ) { $ firstLetter = substr ( $ json_request , 0 , 1 ) ; $ json_request = substr ( $ json_request , 1 ) ; switch ( $ firstLetter ) { case 'c' : $ families = Collection :: make ( explode ( ',' , $ json_request ) ) -> map ( static function ( string $ xref ) use ( $ tree ) : ? Family { return Family :: getInstance ( $ xref , $ tree ) ; } ) -> filter ( ) ; $ r [ ] = $ this -> drawChildren ( $ families , 1 , true ) ; break ; case 'p' : [ $ xref , $ order ] = explode ( '@' , $ json_request ) ; $ family = Family :: getInstance ( $ xref , $ tree ) ; if ( $ family instanceof Family ) { $ parent = $ family -> husband ( ) ?? $ family -> wife ( ) ; if ( $ parent instanceof Individual ) { $ r [ ] = $ this -> drawPerson ( $ parent , 0 , 1 , $ family , $ order , false ) ; } } break ; } } return json_encode ( $ r ) ; }
Return a JSON structure to a JSON request
7,308
private function getPersonDetails ( Individual $ individual , Family $ family = null ) : string { $ chart_url = route ( 'module' , [ 'module' => 'tree' , 'action' => 'Chart' , 'xref' => $ individual -> xref ( ) , 'ged' => $ individual -> tree ( ) -> name ( ) , ] ) ; $ hmtl = $ this -> getThumbnail ( $ individual ) ; $ hmtl .= '<a class="tv_link" href="' . e ( $ individual -> url ( ) ) . '">' . $ individual -> fullName ( ) . '</a> <a href="' . e ( $ chart_url ) . '" title="' . I18N :: translate ( 'Interactive tree of %s' , strip_tags ( $ individual -> fullName ( ) ) ) . '" class="wt-icon-individual tv_link tv_treelink"></a>' ; foreach ( $ individual -> facts ( Gedcom :: BIRTH_EVENTS , true ) as $ fact ) { $ hmtl .= $ fact -> summary ( ) ; } if ( $ family ) { foreach ( $ family -> facts ( Gedcom :: MARRIAGE_EVENTS , true ) as $ fact ) { $ hmtl .= $ fact -> summary ( ) ; } } foreach ( $ individual -> facts ( Gedcom :: DEATH_EVENTS , true ) as $ fact ) { $ hmtl .= $ fact -> summary ( ) ; } return '<div class="tv' . $ individual -> sex ( ) . ' tv_person_expanded">' . $ hmtl . '</div>' ; }
Return the details for a person
7,309
private function drawChildren ( Collection $ familyList , int $ gen = 1 , bool $ ajax = false ) : string { $ html = '' ; $ children2draw = [ ] ; $ f2load = [ ] ; foreach ( $ familyList as $ f ) { $ children = $ f -> children ( ) ; if ( $ children -> isNotEmpty ( ) ) { $ f2load [ ] = $ f -> xref ( ) ; foreach ( $ children as $ child ) { $ children2draw [ $ child -> xref ( ) ] = $ child ; } } } $ tc = count ( $ children2draw ) ; if ( $ tc ) { $ f2load = implode ( ',' , $ f2load ) ; $ nbc = 0 ; foreach ( $ children2draw as $ child ) { $ nbc ++ ; if ( $ tc == 1 ) { $ co = 'c' ; } elseif ( $ nbc == 1 ) { $ co = 't' ; } elseif ( $ nbc == $ tc ) { $ co = 'b' ; } else { $ co = 'h' ; } $ html .= $ this -> drawPerson ( $ child , $ gen - 1 , - 1 , null , $ co , false ) ; } if ( ! $ ajax ) { $ html = '<td align="right"' . ( $ gen == 0 ? ' abbr="c' . $ f2load . '"' : '' ) . '>' . $ html . '</td>' . $ this -> drawHorizontalLine ( ) ; } } return $ html ; }
Draw the children for some families
7,310
private function drawPersonName ( Individual $ individual , string $ dashed ) : string { $ family = $ individual -> primaryChildFamily ( ) ; if ( $ family ) { $ family_name = strip_tags ( $ family -> fullName ( ) ) ; } else { $ family_name = I18N :: translateContext ( 'unknown family' , 'unknown' ) ; } switch ( $ individual -> sex ( ) ) { case 'M' : $ title = ' title="' . I18N :: translate ( 'Son of %s' , $ family_name ) . '"' ; break ; case 'F' : $ title = ' title="' . I18N :: translate ( 'Daughter of %s' , $ family_name ) . '"' ; break ; default : $ title = ' title="' . I18N :: translate ( 'Child of %s' , $ family_name ) . '"' ; break ; } $ sex = $ individual -> sex ( ) ; return '<div class="tv' . $ sex . ' ' . $ dashed . '"' . $ title . '><a href="' . e ( $ individual -> url ( ) ) . '"></a>' . $ individual -> fullName ( ) . ' <span class="dates">' . $ individual -> getLifeSpan ( ) . '</span></div>' ; }
Draw a person name preceded by sex icon with parents as tooltip
7,311
public function value ( ) : string { if ( preg_match ( '/^1 (?:' . $ this -> tag . ') ?(.*(?:(?:\n2 CONT ?.*)*))/' , $ this -> gedcom , $ match ) ) { return preg_replace ( "/\n2 CONT ?/" , "\n" , $ match [ 1 ] ) ; } return '' ; }
Get the value of level 1 data in the fact Allow for multi - line values
7,312
public function target ( ) { $ xref = trim ( $ this -> value ( ) , '@' ) ; switch ( $ this -> tag ) { case 'FAMC' : case 'FAMS' : return Family :: getInstance ( $ xref , $ this -> record ( ) -> tree ( ) ) ; case 'HUSB' : case 'WIFE' : case 'CHIL' : return Individual :: getInstance ( $ xref , $ this -> record ( ) -> tree ( ) ) ; case 'SOUR' : return Source :: getInstance ( $ xref , $ this -> record ( ) -> tree ( ) ) ; case 'OBJE' : return Media :: getInstance ( $ xref , $ this -> record ( ) -> tree ( ) ) ; case 'REPO' : return Repository :: getInstance ( $ xref , $ this -> record ( ) -> tree ( ) ) ; case 'NOTE' : return Note :: getInstance ( $ xref , $ this -> record ( ) -> tree ( ) ) ; default : return GedcomRecord :: getInstance ( $ xref , $ this -> record ( ) -> tree ( ) ) ; } }
Get the record to which this fact links
7,313
public function attribute ( $ tag ) : string { if ( preg_match ( '/\n2 (?:' . $ tag . ') ?(.*(?:(?:\n3 CONT ?.*)*)*)/' , $ this -> gedcom , $ match ) ) { return preg_replace ( "/\n3 CONT ?/" , "\n" , $ match [ 1 ] ) ; } return '' ; }
Get the value of level 2 data in the fact
7,314
public function canShow ( int $ access_level = null ) : bool { if ( $ access_level === null ) { $ access_level = Auth :: accessLevel ( $ this -> record ( ) -> tree ( ) ) ; } if ( strpos ( $ this -> gedcom , "\n2 RESN confidential" ) !== false ) { return Auth :: PRIV_NONE >= $ access_level ; } if ( strpos ( $ this -> gedcom , "\n2 RESN privacy" ) !== false ) { return Auth :: PRIV_USER >= $ access_level ; } if ( strpos ( $ this -> gedcom , "\n2 RESN none" ) !== false ) { return true ; } $ xref = $ this -> record -> xref ( ) ; $ fact_privacy = $ this -> record -> tree ( ) -> getFactPrivacy ( ) ; $ individual_fact_privacy = $ this -> record -> tree ( ) -> getIndividualFactPrivacy ( ) ; if ( isset ( $ individual_fact_privacy [ $ xref ] [ $ this -> tag ] ) ) { return $ individual_fact_privacy [ $ xref ] [ $ this -> tag ] >= $ access_level ; } if ( isset ( $ fact_privacy [ $ this -> tag ] ) ) { return $ fact_privacy [ $ this -> tag ] >= $ access_level ; } return true ; }
Do the privacy rules allow us to display this fact to the current user
7,315
public function canEdit ( ) : bool { if ( $ this -> isPendingDeletion ( ) ) { return false ; } if ( Auth :: isManager ( $ this -> record -> tree ( ) ) ) { return true ; } return Auth :: isEditor ( $ this -> record -> tree ( ) ) && strpos ( $ this -> gedcom , "\n2 RESN locked" ) === false && $ this -> getTag ( ) !== 'RESN' && $ this -> getTag ( ) !== 'CHAN' ; }
Check whether this fact is protected against edit
7,316
public function place ( ) : Place { if ( $ this -> place === null ) { $ this -> place = new Place ( $ this -> attribute ( 'PLAC' ) , $ this -> record ( ) -> tree ( ) ) ; } return $ this -> place ; }
The place where the event occured .
7,317
public function date ( ) : Date { if ( $ this -> date === null ) { $ this -> date = new Date ( $ this -> attribute ( 'DATE' ) ) ; } return $ this -> date ; }
Get the date for this fact . We can call this function many times especially when sorting so keep a copy of the date .
7,318
public function label ( ) : string { if ( ( $ this -> tag === 'FACT' || $ this -> tag === 'EVEN' ) && $ this -> attribute ( 'TYPE' ) !== '' ) { return I18N :: translate ( e ( $ this -> attribute ( 'TYPE' ) ) ) ; } return GedcomTag :: getLabel ( $ this -> tag , $ this -> record ) ; }
Get the name of this fact type for use as a label .
7,319
public function getCitations ( ) : array { preg_match_all ( '/\n(2 SOUR @(' . Gedcom :: REGEX_XREF . ')@(?:\n[3-9] .*)*)/' , $ this -> gedcom ( ) , $ matches , PREG_SET_ORDER ) ; $ citations = [ ] ; foreach ( $ matches as $ match ) { $ source = Source :: getInstance ( $ match [ 2 ] , $ this -> record ( ) -> tree ( ) ) ; if ( $ source && $ source -> canShow ( ) ) { $ citations [ ] = $ match [ 1 ] ; } } return $ citations ; }
Source citations linked to this fact
7,320
public function getMedia ( ) : array { $ media = [ ] ; preg_match_all ( '/\n2 OBJE @(' . Gedcom :: REGEX_XREF . ')@/' , $ this -> gedcom ( ) , $ matches ) ; foreach ( $ matches [ 1 ] as $ match ) { $ obje = Media :: getInstance ( $ match , $ this -> record ( ) -> tree ( ) ) ; if ( $ obje && $ obje -> canShow ( ) ) { $ media [ ] = $ obje ; } } return $ media ; }
Media objects linked to this fact
7,321
private static function dateComparator ( ) : Closure { return static function ( Fact $ a , Fact $ b ) : int { if ( $ a -> date ( ) -> isOK ( ) && $ b -> date ( ) -> isOK ( ) ) { $ ret = Date :: compare ( $ a -> date ( ) , $ b -> date ( ) ) ; if ( $ ret === 0 ) { $ ret = self :: typeComparator ( ) ( $ a , $ b ) ; if ( $ ret === 0 ) { $ ret = $ a -> sortOrder <=> $ b -> sortOrder ; } } return $ ret ; } return $ a -> sortOrder <=> $ b -> sortOrder ; } ; }
Helper functions to sort facts
7,322
public static function typeComparator ( ) : Closure { static $ factsort = [ ] ; if ( empty ( $ factsort ) ) { $ factsort = array_flip ( self :: FACT_ORDER ) ; } return static function ( Fact $ a , Fact $ b ) use ( $ factsort ) : int { if ( $ a -> record instanceof Family && $ b -> record instanceof Family && $ a -> record !== $ b -> record ) { return $ a -> sortOrder - $ b -> sortOrder ; } $ atag = $ a -> getTag ( ) ; $ btag = $ b -> getTag ( ) ; if ( ! array_key_exists ( $ atag , $ factsort ) ) { if ( preg_match ( '/^(_(BIRT|MARR|DEAT|BURI)_)/' , $ atag , $ match ) ) { $ atag = $ match [ 1 ] ; } else { $ atag = '_????_' ; } } if ( ! array_key_exists ( $ btag , $ factsort ) ) { if ( preg_match ( '/^(_(BIRT|MARR|DEAT|BURI)_)/' , $ btag , $ match ) ) { $ btag = $ match [ 1 ] ; } else { $ btag = '_????_' ; } } if ( $ a -> attribute ( 'DATE' ) !== '' && $ factsort [ $ atag ] > $ factsort [ 'BURI' ] && $ factsort [ $ atag ] < $ factsort [ 'CHAN' ] ) { $ atag = 'BURI' ; } if ( $ b -> attribute ( 'DATE' ) !== '' && $ factsort [ $ btag ] > $ factsort [ 'BURI' ] && $ factsort [ $ btag ] < $ factsort [ 'CHAN' ] ) { $ btag = 'BURI' ; } $ ret = $ factsort [ $ atag ] - $ factsort [ $ btag ] ; if ( $ ret == 0 ) { if ( $ a -> attribute ( 'DATE' ) !== '' && $ b -> attribute ( 'DATE' ) === '' ) { return - 1 ; } if ( $ b -> attribute ( 'DATE' ) !== '' && $ a -> attribute ( 'DATE' ) === '' ) { return 1 ; } $ ret = $ a -> sortOrder - $ b -> sortOrder ; } return $ ret ; } ; }
Helper functions to sort facts .
7,323
public static function sortFacts ( Collection $ unsorted ) : Collection { $ dated = [ ] ; $ nondated = [ ] ; $ sorted = [ ] ; $ order = 0 ; foreach ( $ unsorted as $ fact ) { $ fact -> sortOrder = $ order ; $ order ++ ; if ( $ fact -> date ( ) -> isOK ( ) ) { $ dated [ ] = $ fact ; } else { $ nondated [ ] = $ fact ; } } usort ( $ dated , self :: dateComparator ( ) ) ; usort ( $ nondated , self :: typeComparator ( ) ) ; $ dc = count ( $ dated ) ; $ nc = count ( $ nondated ) ; $ i = 0 ; $ j = 0 ; while ( $ i < $ dc ) { if ( $ j < $ nc && self :: typeComparator ( ) ( $ dated [ $ i ] , $ nondated [ $ j ] ) > 0 ) { $ sorted [ ] = $ nondated [ $ j ] ; $ j ++ ; } else { $ sorted [ ] = $ dated [ $ i ] ; $ i ++ ; } } while ( $ j < $ nc ) { $ sorted [ ] = $ nondated [ $ j ] ; $ j ++ ; } return new Collection ( $ sorted ) ; }
A multi - key sort 1 . First divide the facts into two arrays one set with dates and one set without dates 2 . Sort each of the two new arrays the date using the compare date function the non - dated using the compare type function 3 . Then merge the arrays back into the original array using the compare type function
7,324
protected function splitAlignText ( string $ data , int $ maxlen ) : string { $ RTLOrd = [ 215 , 216 , 217 , 218 , 219 , ] ; $ lines = explode ( "\n" , $ data ) ; if ( count ( $ lines ) > 1 ) { $ text = '' ; foreach ( $ lines as $ line ) { $ text .= $ this -> splitAlignText ( $ line , $ maxlen ) . "\n" ; } return $ text ; } $ split = explode ( ' ' , $ data ) ; $ text = '' ; $ line = '' ; $ found = false ; foreach ( $ RTLOrd as $ ord ) { if ( strpos ( $ data , chr ( $ ord ) ) !== false ) { $ found = true ; } } if ( $ found ) { $ line = $ data ; } else { foreach ( $ split as $ word ) { $ len = strlen ( $ line ) ; $ wlen = strlen ( $ word ) ; if ( ( $ len + $ wlen ) < $ maxlen ) { if ( ! empty ( $ line ) ) { $ line .= ' ' ; } $ line .= $ word ; } else { $ p = max ( 0 , ( int ) ( ( $ maxlen - $ len ) / 2 ) ) ; if ( ! empty ( $ line ) ) { $ line = str_repeat ( ' ' , $ p ) . $ line ; $ text .= $ line . "\n" ; } $ line = $ word ; } } } if ( ! empty ( $ line ) ) { $ len = strlen ( $ line ) ; if ( in_array ( ord ( $ line { 0 } ) , $ RTLOrd , true ) ) { $ len /= 2 ; } $ p = max ( 0 , ( int ) ( ( $ maxlen - $ len ) / 2 ) ) ; $ line = str_repeat ( ' ' , $ p ) . $ line ; $ text .= $ line ; } return $ text ; }
split and center text by lines
7,325
protected function imageColor ( $ image , string $ css_color ) : int { return imagecolorallocate ( $ image , ( int ) hexdec ( substr ( $ css_color , 0 , 2 ) ) , ( int ) hexdec ( substr ( $ css_color , 2 , 2 ) ) , ( int ) hexdec ( substr ( $ css_color , 4 , 2 ) ) ) ; }
Convert a CSS color into a GD color .
7,326
public function numberToRomanNumerals ( int $ number ) : string { if ( $ number < 1 ) { return ( string ) $ number ; } $ roman = '' ; foreach ( self :: ROMAN_NUMERALS as $ key => $ value ) { while ( $ number >= $ key ) { $ roman .= $ value ; $ number -= $ key ; } } return $ roman ; }
Convert a decimal number to roman numerals
7,327
public function romanNumeralsToNumber ( string $ roman ) : int { $ num = 0 ; foreach ( self :: ROMAN_NUMERALS as $ key => $ value ) { while ( strpos ( $ roman , $ value ) === 0 ) { $ num += $ key ; $ roman = substr ( $ roman , strlen ( $ value ) ) ; } } return $ num ; }
Convert a roman numeral to decimal
7,328
public function getFavorites ( Tree $ tree ) : array { return DB :: table ( 'favorite' ) -> where ( 'gedcom_id' , '=' , $ tree -> id ( ) ) -> whereNull ( 'user_id' ) -> get ( ) -> map ( static function ( stdClass $ row ) use ( $ tree ) : stdClass { if ( $ row -> xref !== null ) { $ row -> record = GedcomRecord :: getInstance ( $ row -> xref , $ tree ) ; } else { $ row -> record = null ; } return $ row ; } ) -> all ( ) ; }
Get the favorites for a family tree
7,329
private function getPluginList ( ) : array { $ plugins = [ ] ; $ files = glob ( __DIR__ . '/BatchUpdate/BatchUpdate*Plugin.php' , GLOB_NOSORT ) ; foreach ( $ files as $ file ) { $ base_class = basename ( $ file , '.php' ) ; if ( $ base_class !== 'BatchUpdateBasePlugin' ) { $ class = __NAMESPACE__ . '\\BatchUpdate\\' . basename ( $ file , '.php' ) ; $ plugins [ $ class ] = new $ class ( ) ; } } return $ plugins ; }
Scan the plugin folder for a list of plugins
7,330
private function allData ( BatchUpdateBasePlugin $ plugin , Tree $ tree ) : array { $ tmp = [ ] ; foreach ( $ plugin -> getRecordTypesToUpdate ( ) as $ type ) { switch ( $ type ) { case 'INDI' : $ rows = DB :: table ( 'individuals' ) -> where ( 'i_file' , '=' , $ tree -> id ( ) ) -> select ( [ 'i_id AS xref' , DB :: raw ( "'INDI' AS type" ) , 'i_gedcom AS gedcom' ] ) -> get ( ) ; $ tmp = array_merge ( $ tmp , $ rows -> all ( ) ) ; break ; case 'FAM' : $ rows = DB :: table ( 'families' ) -> where ( 'f_file' , '=' , $ tree -> id ( ) ) -> select ( [ 'f_id AS xref' , DB :: raw ( "'FAM' AS type" ) , 'f_gedcom AS gedcom' ] ) -> get ( ) ; $ tmp = array_merge ( $ tmp , $ rows -> all ( ) ) ; break ; case 'SOUR' : $ rows = DB :: table ( 'sources' ) -> where ( 's_file' , '=' , $ tree -> id ( ) ) -> select ( [ 's_id AS xref' , DB :: raw ( "'SOUR' AS type" ) , 's_gedcom AS gedcom' ] ) -> get ( ) ; $ tmp = array_merge ( $ tmp , $ rows -> all ( ) ) ; break ; case 'OBJE' : $ rows = DB :: table ( 'media' ) -> where ( 'm_file' , '=' , $ tree -> id ( ) ) -> select ( [ 'm_id AS xref' , DB :: raw ( "'OBJE' AS type" ) , 'm_gedcom AS gedcom' ] ) -> get ( ) ; $ tmp = array_merge ( $ tmp , $ rows -> all ( ) ) ; break ; default : $ rows = DB :: table ( 'other' ) -> where ( 'o_file' , '=' , $ tree -> id ( ) ) -> where ( 'o_type' , '=' , $ type ) -> select ( [ 'o_id AS xref' , 'o_type AS type' , 'o_gedcom AS gedcom' ] ) -> get ( ) ; $ tmp = array_merge ( $ tmp , $ rows -> all ( ) ) ; break ; } } $ data = [ ] ; foreach ( $ tmp as $ value ) { $ data [ $ value -> xref ] = $ value ; } ksort ( $ tmp ) ; return $ data ; }
Fetch all records that might need updating .
7,331
private function findNextXref ( BatchUpdateBasePlugin $ plugin , string $ xref , array $ all_data , Tree $ tree ) : string { foreach ( array_keys ( $ all_data ) as $ key ) { if ( $ key > $ xref ) { $ record = $ this -> getRecord ( $ all_data [ $ key ] , $ tree ) ; if ( $ plugin -> doesRecordNeedUpdate ( $ record ) ) { return $ key ; } } } return '' ; }
Find the next record that needs to be updated .
7,332
private function findPrevXref ( BatchUpdateBasePlugin $ plugin , string $ xref , array $ all_data , Tree $ tree ) : string { foreach ( array_reverse ( $ all_data ) as $ key => $ value ) { if ( $ key > $ xref ) { $ record = $ this -> getRecord ( $ all_data [ $ key ] , $ tree ) ; if ( $ plugin -> doesRecordNeedUpdate ( $ record ) ) { return $ key ; } } } return '' ; }
Find the previous record that needs to be updated .
7,333
public function getStart ( ) : string { $ str = '<' . $ this -> tag . ' ' ; foreach ( $ this -> attrs as $ key => $ value ) { $ str .= $ key . '="' . $ value . '" ' ; } $ str .= '>' ; return $ str ; }
Get the start tag .
7,334
public function render ( $ renderer ) { $ renderer -> clearPageHeader ( ) ; foreach ( $ this -> elements as $ element ) { $ renderer -> addPageHeader ( $ element ) ; } }
PageHeader element renderer
7,335
private function allMediaFolders ( ) : Collection { $ base_folders = DB :: table ( 'gedcom_setting' ) -> where ( 'setting_name' , '=' , 'MEDIA_DIRECTORY' ) -> select ( DB :: raw ( "setting_value || 'dummy.jpeg' AS path" ) ) ; return DB :: table ( 'media_file' ) -> join ( 'gedcom_setting' , 'gedcom_id' , '=' , 'm_file' ) -> where ( 'setting_name' , '=' , 'MEDIA_DIRECTORY' ) -> where ( 'multimedia_file_refn' , 'LIKE' , '%/%' ) -> where ( 'multimedia_file_refn' , 'NOT LIKE' , 'http://%' ) -> where ( 'multimedia_file_refn' , 'NOT LIKE' , 'https://%' ) -> select ( DB :: raw ( 'setting_value || multimedia_file_refn AS path' ) ) -> union ( $ base_folders ) -> pluck ( 'path' ) -> map ( static function ( string $ path ) : string { return dirname ( $ path ) . '/' ; } ) -> unique ( ) -> sort ( ) -> mapWithKeys ( static function ( string $ path ) : array { return [ $ path => $ path ] ; } ) ; }
Generate a list of all folders from all the trees .
7,336
private function allDiskFiles ( string $ media_folder , string $ subfolders ) : array { return $ this -> scanFolders ( WT_DATA_DIR . $ media_folder , $ subfolders === 'include' ) ; }
Fetch a list of all files on disk
7,337
private function mediaObjectInfo ( Media $ media ) : string { $ html = '<b><a href="' . e ( $ media -> url ( ) ) . '">' . $ media -> fullName ( ) . '</a></b>' . '<br><i>' . e ( $ media -> getNote ( ) ) . '</i></br><br>' ; $ linked = [ ] ; foreach ( $ media -> linkedIndividuals ( 'OBJE' ) as $ link ) { $ linked [ ] = '<a href="' . e ( $ link -> url ( ) ) . '">' . $ link -> fullName ( ) . '</a>' ; } foreach ( $ media -> linkedFamilies ( 'OBJE' ) as $ link ) { $ linked [ ] = '<a href="' . e ( $ link -> url ( ) ) . '">' . $ link -> fullName ( ) . '</a>' ; } foreach ( $ media -> linkedSources ( 'OBJE' ) as $ link ) { $ linked [ ] = '<a href="' . e ( $ link -> url ( ) ) . '">' . $ link -> fullName ( ) . '</a>' ; } foreach ( $ media -> linkedNotes ( 'OBJE' ) as $ link ) { $ linked [ ] = '<a href="' . e ( $ link -> url ( ) ) . '">' . $ link -> fullName ( ) . '</a>' ; } foreach ( $ media -> linkedRepositories ( 'OBJE' ) as $ link ) { $ linked [ ] = '<a href="' . e ( $ link -> url ( ) ) . '">' . $ link -> fullName ( ) . '</a>' ; } if ( ! empty ( $ linked ) ) { $ html .= '<ul>' ; foreach ( $ linked as $ link ) { $ html .= '<li>' . $ link . '</li>' ; } $ html .= '</ul>' ; } else { $ html .= '<div class="alert alert-danger">' . I18N :: translate ( 'There are no links to this media object.' ) . '</div>' ; } return $ html ; }
Generate some useful information and links about a media object .
7,338
private function allMediaFiles ( string $ media_folder , string $ subfolders ) : array { $ query = DB :: table ( 'media_file' ) -> join ( 'gedcom_setting' , 'gedcom_id' , '=' , 'm_file' ) -> where ( 'setting_name' , '=' , 'MEDIA_DIRECTORY' ) -> where ( 'multimedia_file_refn' , 'LIKE' , '%/%' ) -> where ( 'multimedia_file_refn' , 'NOT LIKE' , 'http://%' ) -> where ( 'multimedia_file_refn' , 'NOT LIKE' , 'https://%' ) -> where ( DB :: raw ( 'setting_value || multimedia_file_refn' ) , 'LIKE' , $ media_folder . '%' ) -> select ( DB :: raw ( 'setting_value || multimedia_file_refn AS path' ) ) -> orderBy ( DB :: raw ( 'setting_value || multimedia_file_refn' ) ) ; if ( $ subfolders === 'exclude' ) { $ query -> where ( DB :: raw ( 'setting_value || multimedia_file_refn' ) , 'NOT LIKE' , $ media_folder . '%/%' ) ; } return $ query -> pluck ( 'path' ) -> all ( ) ; }
Fetch a list of all files on in the database .
7,339
public static function send ( UserInterface $ from , UserInterface $ to , UserInterface $ reply_to , $ subject , $ message_text , $ message_html ) : bool { try { $ message_text = preg_replace ( '/\r?\n/' , "\r\n" , $ message_text ) ; $ message_html = preg_replace ( '/\r?\n/' , "\r\n" , $ message_html ) ; $ message = ( new Swift_Message ( $ subject ) ) -> setFrom ( $ from -> email ( ) , $ from -> realName ( ) ) -> setTo ( $ to -> email ( ) , $ to -> realName ( ) ) -> setReplyTo ( $ reply_to -> email ( ) , $ reply_to -> realName ( ) ) -> setBody ( $ message_html , 'text/html' ) -> addPart ( $ message_text , 'text/plain' ) ; $ mailer = new Swift_Mailer ( self :: transport ( ) ) ; $ mailer -> send ( $ message ) ; } catch ( Exception $ ex ) { Log :: addErrorLog ( 'Mail: ' . $ ex -> getMessage ( ) ) ; return false ; } return true ; }
Send an external email message Caution! gmail may rewrite the From header unless you have added the address to your account .
7,340
public static function transport ( ) : Swift_Transport { switch ( Site :: getPreference ( 'SMTP_ACTIVE' ) ) { case 'sendmail' : return new Swift_SendmailTransport ( ) ; case 'external' : $ smtp_host = Site :: getPreference ( 'SMTP_HOST' ) ; $ smtp_port = ( int ) Site :: getPreference ( 'SMTP_PORT' , '25' ) ; $ smtp_auth = Site :: getPreference ( 'SMTP_AUTH' ) ; $ smtp_user = Site :: getPreference ( 'SMTP_AUTH_USER' ) ; $ smtp_pass = Site :: getPreference ( 'SMTP_AUTH_PASS' ) ; $ smtp_encr = Site :: getPreference ( 'SMTP_SSL' ) ; $ transport = new Swift_SmtpTransport ( $ smtp_host , $ smtp_port , $ smtp_encr ) ; $ transport -> setLocalDomain ( Site :: getPreference ( 'SMTP_HELO' ) ) ; if ( $ smtp_auth ) { $ transport -> setUsername ( $ smtp_user ) -> setPassword ( $ smtp_pass ) ; } return $ transport ; default : return new Swift_NullTransport ( ) ; } }
Create a transport mechanism for sending mail
7,341
public static function optionsRestrictions ( $ include_empty ) : array { $ options = [ 'none' => I18N :: translate ( 'Show to visitors' ) , 'privacy' => I18N :: translate ( 'Show to members' ) , 'confidential' => I18N :: translate ( 'Show to managers' ) , 'locked' => I18N :: translate ( 'Only managers can edit' ) , ] ; if ( $ include_empty ) { $ options = [ '' => '' ] + $ options ; } return $ options ; }
A list of GEDCOM restrictions for inline data .
7,342
public static function optionsRestrictionsRule ( ) : array { $ options = [ 'none' => I18N :: translate ( 'Show to visitors' ) , 'privacy' => I18N :: translate ( 'Show to members' ) , 'confidential' => I18N :: translate ( 'Show to managers' ) , 'hidden' => I18N :: translate ( 'Hide from everyone' ) , ] ; return $ options ; }
A list of GEDCOM restrictions for privacy rules .
7,343
public static function addSimpleTags ( Tree $ tree , $ fact ) : void { if ( $ fact === 'MARR' ) { echo self :: addSimpleTag ( $ tree , '0 ' . $ fact . ' Y' ) ; } else { echo self :: addSimpleTag ( $ tree , '0 ' . $ fact ) ; } if ( ! in_array ( $ fact , Config :: nonDateFacts ( ) , true ) ) { echo self :: addSimpleTag ( $ tree , '0 DATE' , $ fact , GedcomTag :: getLabel ( $ fact . ':DATE' ) ) ; echo self :: addSimpleTag ( $ tree , '0 RELI' , $ fact , GedcomTag :: getLabel ( $ fact . ':RELI' ) ) ; } if ( ! in_array ( $ fact , Config :: nonPlaceFacts ( ) , true ) ) { echo self :: addSimpleTag ( $ tree , '0 PLAC' , $ fact , GedcomTag :: getLabel ( $ fact . ':PLAC' ) ) ; if ( preg_match_all ( '/(' . Gedcom :: REGEX_TAG . ')/' , $ tree -> getPreference ( 'ADVANCED_PLAC_FACTS' ) , $ match ) ) { foreach ( $ match [ 1 ] as $ tag ) { echo self :: addSimpleTag ( $ tree , '0 ' . $ tag , $ fact , GedcomTag :: getLabel ( $ fact . ':PLAC:' . $ tag ) ) ; } } echo self :: addSimpleTag ( $ tree , '0 MAP' , $ fact ) ; echo self :: addSimpleTag ( $ tree , '0 LATI' , $ fact ) ; echo self :: addSimpleTag ( $ tree , '0 LONG' , $ fact ) ; } }
Add some empty tags to create a new fact .
7,344
public static function createAddForm ( Tree $ tree , $ fact ) : void { self :: $ tags = [ ] ; if ( substr ( $ fact , 0 , 5 ) === 'MARR_' ) { self :: $ tags [ 0 ] = 'MARR' ; echo self :: addSimpleTag ( $ tree , '1 MARR' ) ; self :: insertMissingSubtags ( $ tree , $ fact ) ; } else { self :: $ tags [ 0 ] = $ fact ; if ( $ fact === '_UID' ) { $ fact .= ' ' . GedcomTag :: createUid ( ) ; } if ( in_array ( $ fact , [ 'ALIA' , 'ASSO' , ] ) ) { $ fact .= ' @' ; } if ( in_array ( $ fact , Config :: emptyFacts ( ) , true ) ) { echo self :: addSimpleTag ( $ tree , '1 ' . $ fact . ' Y' ) ; } else { echo self :: addSimpleTag ( $ tree , '1 ' . $ fact ) ; } self :: insertMissingSubtags ( $ tree , self :: $ tags [ 0 ] ) ; if ( $ fact === 'SOUR' ) { echo self :: addSimpleTag ( $ tree , '2 PAGE' ) ; echo self :: addSimpleTag ( $ tree , '2 DATA' ) ; echo self :: addSimpleTag ( $ tree , '3 TEXT' ) ; if ( $ tree -> getPreference ( 'FULL_SOURCES' ) ) { echo self :: addSimpleTag ( $ tree , '3 DATE' , '' , GedcomTag :: getLabel ( 'DATA:DATE' ) ) ; echo self :: addSimpleTag ( $ tree , '2 QUAY' ) ; } } } }
builds the form for adding new facts
7,345
public function getNote ( ) : string { if ( preg_match ( '/^0 @' . Gedcom :: REGEX_XREF . '@ NOTE ?(.*(?:\n1 CONT ?.*)*)/' , $ this -> gedcom . $ this -> pending , $ match ) ) { return preg_replace ( "/\n1 CONT ?/" , "\n" , $ match [ 1 ] ) ; } return '' ; }
Get the text contents of the note
7,346
private function whereFamily ( bool $ fams , Builder $ query ) : void { if ( $ fams ) { $ query -> join ( 'link' , static function ( JoinClause $ join ) : void { $ join -> on ( 'l_from' , '=' , 'n_id' ) -> on ( 'l_file' , '=' , 'n_file' ) -> where ( 'l_type' , '=' , 'FAMS' ) ; } ) ; } }
Restrict a query to individuals that are a spouse in a family record .
7,347
public function surnameAlpha ( bool $ marnm , bool $ fams , string $ locale , string $ collation ) : array { $ n_surn = $ this -> fieldWithCollation ( 'n_surn' , $ collation ) ; $ alphas = [ ] ; $ query = DB :: table ( 'name' ) -> where ( 'n_file' , '=' , $ this -> tree -> id ( ) ) ; $ this -> whereFamily ( $ fams , $ query ) ; $ this -> whereMarriedName ( $ marnm , $ query ) ; foreach ( $ this -> localization_service -> alphabet ( ) as $ letter ) { $ query2 = clone $ query ; $ this -> whereInitial ( $ query2 , 'n_surn' , $ letter , $ locale , $ collation ) ; $ alphas [ $ letter ] = $ query2 -> count ( ) ; } $ query2 = clone $ query ; foreach ( $ this -> localization_service -> alphabet ( ) as $ n => $ letter ) { $ query2 -> where ( $ n_surn , 'NOT LIKE' , $ letter . '%' ) ; } $ rows = $ query2 -> select ( [ DB :: raw ( 'SUBSTR(n_surn, 1, 1) AS initial' ) , DB :: raw ( 'COUNT(*) AS count' ) ] ) -> groupBy ( 'initial' ) -> orderBy ( DB :: raw ( "CASE initial WHEN '' THEN 1 ELSE 0 END" ) ) -> orderBy ( DB :: raw ( "CASE initial WHEN '@' THEN 1 ELSE 0 END" ) ) -> orderBy ( 'initial' ) -> pluck ( 'count' , 'initial' ) ; foreach ( $ rows as $ alpha => $ count ) { $ alphas [ $ alpha ] = ( int ) $ count ; } $ count_no_surname = $ query -> where ( 'n_surn' , '=' , '' ) -> count ( ) ; if ( $ count_no_surname !== 0 ) { $ alphas [ ',' ] = $ count_no_surname ; } return $ alphas ; }
Get a list of initial surname letters .
7,348
public function givenAlpha ( string $ surn , string $ salpha , bool $ marnm , bool $ fams , string $ locale , string $ collation ) : array { $ alphas = [ ] ; $ query = DB :: table ( 'name' ) -> where ( 'n_file' , '=' , $ this -> tree -> id ( ) ) ; $ this -> whereFamily ( $ fams , $ query ) ; $ this -> whereMarriedName ( $ marnm , $ query ) ; if ( $ surn !== '' ) { $ n_surn = $ this -> fieldWithCollation ( 'n_surn' , $ collation ) ; $ query -> where ( $ n_surn , '=' , $ surn ) ; } elseif ( $ salpha === ',' ) { $ query -> where ( 'n_surn' , '=' , '' ) ; } elseif ( $ salpha === '@' ) { $ query -> where ( 'n_surn' , '=' , '@N.N.' ) ; } elseif ( $ salpha !== '' ) { $ this -> whereInitial ( $ query , 'n_surn' , $ salpha , $ locale , $ collation ) ; } else { $ query -> whereNotIn ( 'n_surn' , [ '' , '@N.N.' ] ) ; } foreach ( $ this -> localization_service -> alphabet ( ) as $ letter ) { $ query2 = clone $ query ; $ this -> whereInitial ( $ query2 , 'n_givn' , $ letter , $ locale , $ collation ) ; $ alphas [ $ letter ] = ( int ) $ query2 -> distinct ( ) -> count ( 'n_id' ) ; } $ rows = $ query -> select ( [ DB :: raw ( 'UPPER(SUBSTR(n_givn, 1, 1)) AS initial' ) , DB :: raw ( 'COUNT(*) AS count' ) ] ) -> groupBy ( 'initial' ) -> orderBy ( DB :: raw ( "CASE initial WHEN '' THEN 1 ELSE 0 END" ) ) -> orderBy ( DB :: raw ( "CASE initial WHEN '@' THEN 1 ELSE 0 END" ) ) -> orderBy ( 'initial' ) -> pluck ( 'count' , 'initial' ) ; foreach ( $ rows as $ alpha => $ count ) { $ alphas [ $ alpha ] = ( int ) $ count ; } return $ alphas ; }
Get a list of initial given name letters for indilist . php and famlist . php
7,349
public function surnames ( string $ surn , string $ salpha , bool $ marnm , bool $ fams , string $ locale , string $ collation ) : array { $ query = DB :: table ( 'name' ) -> where ( 'n_file' , '=' , $ this -> tree -> id ( ) ) -> select ( [ DB :: raw ( 'UPPER(n_surn /*! COLLATE ' . I18N :: collation ( ) . ' */) AS n_surn' ) , DB :: raw ( 'n_surname /*! COLLATE utf8_bin */ AS n_surname' ) , DB :: raw ( 'COUNT(*) AS total' ) , ] ) -> groupBy ( [ 'n_surn' ] ) -> groupBy ( [ 'n_surname' ] ) -> orderBy ( 'n_surname' ) ; $ this -> whereFamily ( $ fams , $ query ) ; $ this -> whereMarriedName ( $ marnm , $ query ) ; if ( $ surn !== '' ) { $ query -> where ( 'n_surn' , '=' , $ surn ) ; } elseif ( $ salpha === ',' ) { $ query -> where ( 'n_surn' , '=' , '' ) ; } elseif ( $ salpha === '@' ) { $ query -> where ( 'n_surn' , '=' , '@N.N.' ) ; } elseif ( $ salpha !== '' ) { $ this -> whereInitial ( $ query , 'n_surn' , $ salpha , $ locale , $ collation ) ; } else { $ query -> whereNotIn ( 'n_surn' , [ '' , '@N.N.' ] ) ; } $ query -> groupBy ( [ 'n_surn' ] ) -> groupBy ( [ 'n_surname' ] ) ; $ list = [ ] ; foreach ( $ query -> get ( ) as $ row ) { $ list [ $ row -> n_surn ] [ $ row -> n_surname ] = ( int ) $ row -> total ; } return $ list ; }
Get a count of actual surnames and variants based on a root surname .
7,350
private function fieldWithCollation ( string $ field , string $ collation ) : Expression { return DB :: raw ( $ field . ' /*! COLLATE ' . $ collation . ' */' ) ; }
Use MySQL - specific comments so we can run these queries on other RDBMS .
7,351
private function whereInitial ( Builder $ query , string $ field , string $ letter , string $ locale , string $ collation ) : void { $ field_with_collation = $ this -> fieldWithCollation ( $ field , $ collation ) ; switch ( $ locale ) { case 'cs' : $ this -> whereInitialCzech ( $ query , $ field_with_collation , $ letter ) ; break ; case 'da' : case 'nb' : case 'nn' : $ this -> whereInitialNorwegian ( $ query , $ field_with_collation , $ letter ) ; break ; case 'sv' : case 'fi' : $ this -> whereInitialSwedish ( $ query , $ field_with_collation , $ letter ) ; break ; case 'hu' : $ this -> whereInitialHungarian ( $ query , $ field_with_collation , $ letter ) ; break ; case 'nl' : $ this -> whereInitialDutch ( $ query , $ field_with_collation , $ letter ) ; break ; default : $ query -> where ( $ field_with_collation , 'LIKE' , '\\' . $ letter . '%' ) ; } }
Modify a query to restrict a field to a given initial letter . Take account of digraphs equialent letters etc .
7,352
private function whereInitialHungarian ( Builder $ query , Expression $ field , string $ letter ) : void { switch ( $ letter ) { case 'C' : $ query -> where ( $ field , 'LIKE' , 'C%' ) -> where ( $ field , 'NOT LIKE' , 'CS%' ) ; break ; case 'D' : $ query -> where ( $ field , 'LIKE' , 'D%' ) -> where ( $ field , 'NOT LIKE' , 'DZ%' ) ; break ; case 'DZ' : $ query -> where ( $ field , 'LIKE' , 'DZ%' ) -> where ( $ field , 'NOT LIKE' , 'DZS%' ) ; break ; case 'G' : $ query -> where ( $ field , 'LIKE' , 'G%' ) -> where ( $ field , 'NOT LIKE' , 'GY%' ) ; break ; case 'L' : $ query -> where ( $ field , 'LIKE' , 'L%' ) -> where ( $ field , 'NOT LIKE' , 'LY%' ) ; break ; case 'N' : $ query -> where ( $ field , 'LIKE' , 'N%' ) -> where ( $ field , 'NOT LIKE' , 'NY%' ) ; break ; case 'S' : $ query -> where ( $ field , 'LIKE' , 'S%' ) -> where ( $ field , 'NOT LIKE' , 'SZ%' ) ; break ; case 'T' : $ query -> where ( $ field , 'LIKE' , 'T%' ) -> where ( $ field , 'NOT LIKE' , 'TY%' ) ; break ; case 'Z' : $ query -> where ( $ field , 'LIKE' , 'Z%' ) -> where ( $ field , 'NOT LIKE' , 'ZS%' ) ; break ; default : $ query -> where ( $ field , 'LIKE' , '\\' . $ letter . '%' ) ; break ; } }
Hungarian has many digraphs and trigraphs so exclude these from prefixes .
7,353
public static function getValues ( GedcomRecord $ record = null ) : array { $ values = [ ] ; foreach ( self :: TYPES as $ type ) { $ values [ $ type ] = self :: getValue ( $ type , $ record ) ; } uasort ( $ values , '\Fisharebest\Webtrees\I18N::strcasecmp' ) ; return $ values ; }
A list of all possible values for RELA
7,354
private function commonGivenQuery ( string $ sex , string $ type , bool $ show_tot , int $ threshold , int $ maxtoshow ) { $ query = DB :: table ( 'name' ) -> join ( 'individuals' , static function ( JoinClause $ join ) : void { $ join -> on ( 'i_file' , '=' , 'n_file' ) -> on ( 'i_id' , '=' , 'n_id' ) ; } ) -> where ( 'n_file' , '=' , $ this -> tree -> id ( ) ) -> where ( 'n_type' , '<>' , '_MARNM' ) -> where ( 'n_givn' , '<>' , '@P.N.' ) -> where ( DB :: raw ( 'LENGTH(n_givn)' ) , '>' , 1 ) ; switch ( $ sex ) { case 'M' : case 'F' : case 'U' : $ query -> where ( 'i_sex' , '=' , $ sex ) ; break ; case 'B' : default : $ query -> where ( 'i_sex' , '<>' , 'U' ) ; break ; } $ rows = $ query -> groupBy ( [ 'n_givn' ] ) -> select ( [ 'n_givn' , DB :: raw ( 'COUNT(distinct n_id) AS count' ) ] ) -> pluck ( 'count' , 'n_givn' ) ; $ nameList = [ ] ; foreach ( $ rows as $ n_givn => $ count ) { foreach ( explode ( ' ' , $ n_givn ) as $ given ) { if ( ! preg_match ( '/^([A-Z]|[a-z]{1,3})$/' , $ given ) ) { if ( array_key_exists ( $ given , $ nameList ) ) { $ nameList [ $ given ] += ( int ) $ count ; } else { $ nameList [ $ given ] = ( int ) $ count ; } } } } arsort ( $ nameList ) ; $ nameList = array_slice ( $ nameList , 0 , $ maxtoshow ) ; foreach ( $ nameList as $ given => $ total ) { if ( $ total < $ threshold ) { unset ( $ nameList [ $ given ] ) ; } } switch ( $ type ) { case 'chart' : return $ nameList ; case 'table' : return view ( 'lists/given-names-table' , [ 'given_names' => $ nameList , ] ) ; case 'list' : return view ( 'lists/given-names-list' , [ 'given_names' => $ nameList , 'show_totals' => $ show_tot , ] ) ; case 'nolist' : default : array_walk ( $ nameList , static function ( string & $ value , string $ key ) use ( $ show_tot ) : void { if ( $ show_tot ) { $ value = '<span dir="auto">' . e ( $ key ) . '</span>' ; } else { $ value = '<span dir="auto">' . e ( $ key ) . '</span> (' . I18N :: number ( ( int ) $ value ) . ')' ; } } ) ; return implode ( I18N :: $ list_separator , $ nameList ) ; } }
Find common given names .
7,355
public function statsBirthBySexQuery ( int $ year1 = - 1 , int $ year2 = - 1 ) : Builder { return $ this -> statsBirthQuery ( $ year1 , $ year2 ) -> select ( [ 'd_month' , 'i_sex' , DB :: raw ( 'COUNT(*) AS total' ) ] ) -> join ( 'individuals' , static function ( JoinClause $ join ) : void { $ join -> on ( 'i_id' , '=' , 'd_gid' ) -> on ( 'i_file' , '=' , 'd_file' ) ; } ) -> groupBy ( 'i_sex' ) ; }
Get a count of births by month .
7,356
public function statsBirth ( string $ color_from = null , string $ color_to = null ) : string { return ( new ChartBirth ( $ this -> tree ) ) -> chartBirth ( $ color_from , $ color_to ) ; }
General query on births .
7,357
public function statsDeathBySexQuery ( int $ year1 = - 1 , int $ year2 = - 1 ) : Builder { return $ this -> statsDeathQuery ( $ year1 , $ year2 ) -> select ( [ 'd_month' , 'i_sex' , DB :: raw ( 'COUNT(*) AS total' ) ] ) -> join ( 'individuals' , static function ( JoinClause $ join ) : void { $ join -> on ( 'i_id' , '=' , 'd_gid' ) -> on ( 'i_file' , '=' , 'd_file' ) ; } ) -> groupBy ( 'i_sex' ) ; }
Get a list of death dates .
7,358
public function statsDeath ( string $ color_from = null , string $ color_to = null ) : string { return ( new ChartDeath ( $ this -> tree ) ) -> chartDeath ( $ color_from , $ color_to ) ; }
General query on deaths .
7,359
public function statsAgeQuery ( string $ related = 'BIRT' , string $ sex = 'BOTH' , int $ year1 = - 1 , int $ year2 = - 1 ) { $ prefix = DB :: connection ( ) -> getTablePrefix ( ) ; $ query = $ this -> birthAndDeathQuery ( $ sex ) ; if ( $ year1 >= 0 && $ year2 >= 0 ) { $ query -> whereIn ( 'birth.d_type' , [ '@#DGREGORIAN@' , '@#DJULIAN@' ] ) -> whereIn ( 'death.d_type' , [ '@#DGREGORIAN@' , '@#DJULIAN@' ] ) ; if ( $ related === 'BIRT' ) { $ query -> whereBetween ( 'birth.d_year' , [ $ year1 , $ year2 ] ) ; } elseif ( $ related === 'DEAT' ) { $ query -> whereBetween ( 'death.d_year' , [ $ year1 , $ year2 ] ) ; } } return $ query -> select ( DB :: raw ( $ prefix . 'death.d_julianday2 - ' . $ prefix . 'birth.d_julianday1 AS days' ) ) -> orderBy ( 'days' , 'desc' ) -> get ( ) -> all ( ) ; }
General query on ages .
7,360
public function topTenOldestFemale ( int $ total = 10 ) : string { $ records = $ this -> topTenOldestQuery ( 'F' , $ total ) ; return view ( 'statistics/individuals/top10-nolist' , [ 'records' => $ records , ] ) ; }
Find the oldest females .
7,361
public function topTenOldestFemaleList ( int $ total = 10 ) : string { $ records = $ this -> topTenOldestQuery ( 'F' , $ total ) ; return view ( 'statistics/individuals/top10-list' , [ 'records' => $ records , ] ) ; }
Find the oldest living females .
7,362
private function averageLifespanQuery ( string $ sex , bool $ show_years ) : string { $ prefix = DB :: connection ( ) -> getTablePrefix ( ) ; $ days = ( int ) $ this -> birthAndDeathQuery ( $ sex ) -> select ( DB :: raw ( 'AVG(' . $ prefix . 'death.d_julianday2 - ' . $ prefix . 'birth.d_julianday1) AS days' ) ) -> value ( 'days' ) ; if ( $ show_years ) { return $ this -> calculateAge ( $ days ) ; } return I18N :: number ( ( int ) ( $ days / 365.25 ) ) ; }
Find the average lifespan .
7,363
private function getPercentage ( int $ count , int $ total ) : string { return ( $ total !== 0 ) ? I18N :: percentage ( $ count / $ total , 1 ) : '' ; }
Convert totals into percentages .
7,364
private function totalLivingQuery ( ) : int { $ query = DB :: table ( 'individuals' ) -> where ( 'i_file' , '=' , $ this -> tree -> id ( ) ) ; foreach ( Gedcom :: DEATH_EVENTS as $ death_event ) { $ query -> where ( 'i_gedcom' , 'NOT LIKE' , "%\n1 " . $ death_event . '%' ) ; } return $ query -> count ( ) ; }
Count the number of living individuals .
7,365
private function totalDeceasedQuery ( ) : int { return DB :: table ( 'individuals' ) -> where ( 'i_file' , '=' , $ this -> tree -> id ( ) ) -> where ( static function ( Builder $ query ) : void { foreach ( Gedcom :: DEATH_EVENTS as $ death_event ) { $ query -> orWhere ( 'i_gedcom' , 'LIKE' , "%\n1 " . $ death_event . '%' ) ; } } ) -> count ( ) ; }
Count the number of dead individuals .
7,366
private function getTotalSexQuery ( string $ sex ) : int { return DB :: table ( 'individuals' ) -> where ( 'i_file' , '=' , $ this -> tree -> id ( ) ) -> where ( 'i_sex' , '=' , $ sex ) -> count ( ) ; }
Returns the total count of a specific sex .
7,367
private function totalIndisWithSourcesQuery ( ) : int { return DB :: table ( 'individuals' ) -> select ( [ 'i_id' ] ) -> distinct ( ) -> join ( 'link' , static function ( JoinClause $ join ) : void { $ join -> on ( 'i_id' , '=' , 'l_from' ) -> on ( 'i_file' , '=' , 'l_file' ) ; } ) -> where ( 'l_file' , '=' , $ this -> tree -> id ( ) ) -> where ( 'l_type' , '=' , 'SOUR' ) -> count ( 'i_id' ) ; }
How many individuals have one or more sources .
7,368
private function totalRecordsQuery ( ) : int { return $ this -> totalIndividualsQuery ( ) + $ this -> totalFamiliesQuery ( ) + $ this -> totalNotesQuery ( ) + $ this -> totalRepositoriesQuery ( ) + $ this -> totalSourcesQuery ( ) ; }
Returns the total number of records .
7,369
private function birthAndDeathQuery ( string $ sex ) : Builder { $ query = DB :: table ( 'individuals' ) -> where ( 'i_file' , '=' , $ this -> tree -> id ( ) ) -> join ( 'dates AS birth' , static function ( JoinClause $ join ) : void { $ join -> on ( 'birth.d_file' , '=' , 'i_file' ) -> on ( 'birth.d_gid' , '=' , 'i_id' ) ; } ) -> join ( 'dates AS death' , static function ( JoinClause $ join ) : void { $ join -> on ( 'death.d_file' , '=' , 'i_file' ) -> on ( 'death.d_gid' , '=' , 'i_id' ) ; } ) -> where ( 'birth.d_fact' , '=' , 'BIRT' ) -> where ( 'death.d_fact' , '=' , 'DEAT' ) -> whereColumn ( 'death.d_julianday1' , '>=' , 'birth.d_julianday2' ) -> where ( 'birth.d_julianday2' , '<>' , 0 ) ; if ( $ sex === 'M' || $ sex === 'F' ) { $ query -> where ( 'i_sex' , '=' , $ sex ) ; } return $ query ; }
Query individuals with their births and deaths .
7,370
public function parent ( ) : Place { return new self ( $ this -> parts -> slice ( 1 ) -> implode ( Gedcom :: PLACE_SEPARATOR ) , $ this -> tree ) ; }
Get the higher level place .
7,371
public function getChildPlaces ( ) : array { if ( $ this -> place_name !== '' ) { $ parent_text = Gedcom :: PLACE_SEPARATOR . $ this -> place_name ; } else { $ parent_text = '' ; } return DB :: table ( 'places' ) -> where ( 'p_file' , '=' , $ this -> tree -> id ( ) ) -> where ( 'p_parent_id' , '=' , $ this -> id ( ) ) -> orderBy ( DB :: raw ( 'p_place /*! COLLATE ' . I18N :: collation ( ) . ' */' ) ) -> pluck ( 'p_place' ) -> map ( function ( string $ place ) use ( $ parent_text ) : Place { return new self ( $ place . $ parent_text , $ this -> tree ) ; } ) -> all ( ) ; }
Get the lower level places .
7,372
public function url ( ) : string { $ module = app ( ModuleService :: class ) -> findByComponent ( ModuleListInterface :: class , $ this -> tree , Auth :: user ( ) ) -> first ( static function ( ModuleInterface $ module ) : bool { return $ module instanceof PlaceHierarchyListModule ; } ) ; if ( $ module instanceof PlaceHierarchyListModule ) { return $ module -> listUrl ( $ this -> tree , [ 'parent' => $ this -> parts -> reverse ( ) -> all ( ) , 'ged' => $ this -> tree -> name ( ) , ] ) ; } return '#' ; }
Create a URL to the place - hierarchy page .
7,373
public function placeName ( ) : string { $ place_name = $ this -> parts -> first ( ) ?? I18N :: translate ( 'unknown' ) ; return '<span dir="auto">' . e ( $ place_name ) . '</span>' ; }
Format this place for display on screen .
7,374
public function fullName ( bool $ link = false ) : string { if ( $ this -> parts -> isEmpty ( ) ) { return '' ; } $ full_name = $ this -> parts -> implode ( I18N :: $ list_separator ) ; if ( $ link ) { return '<a dir="auto" href="' . e ( $ this -> url ( ) ) . '">' . e ( $ full_name ) . '</a>' ; } return '<span dir="auto">' . e ( $ full_name ) . '</span>' ; }
Generate the place name for display including the full hierarchy .
7,375
public static function marriageDateComparator ( ) : Closure { return static function ( Family $ x , Family $ y ) : int { return Date :: compare ( $ x -> getMarriageDate ( ) , $ y -> getMarriageDate ( ) ) ; } ; }
A closure which will compare families by marriage date .
7,376
public function spouse ( Individual $ person , $ access_level = null ) : ? Individual { if ( $ person === $ this -> wife ) { return $ this -> husband ( $ access_level ) ; } return $ this -> wife ( $ access_level ) ; }
Find the spouse of a person .
7,377
public function numberOfChildren ( ) : int { $ nchi = $ this -> children ( ) -> count ( ) ; foreach ( $ this -> facts ( [ 'NCHI' ] ) as $ fact ) { $ nchi = max ( $ nchi , ( int ) $ fact -> value ( ) ) ; } return $ nchi ; }
Number of children - for the individual list
7,378
public function getMarriagePlace ( ) : Place { $ marriage = $ this -> getMarriage ( ) ; if ( $ marriage instanceof Fact ) { return $ marriage -> place ( ) ; } return new Place ( '' , $ this -> tree ) ; }
Get the marriage place
7,379
public function getAllMarriagePlaces ( ) : array { foreach ( Gedcom :: MARRIAGE_EVENTS as $ event ) { $ places = $ this -> getAllEventPlaces ( [ $ event ] ) ; if ( ! empty ( $ places ) ) { return $ places ; } } return [ ] ; }
Get a list of all marriage places - for the family lists .
7,380
public function verify ( ServerRequestInterface $ request , Tree $ tree , UserService $ user_service ) : ResponseInterface { $ username = $ request -> get ( 'username' , '' ) ; $ token = $ request -> get ( 'token' , '' ) ; $ title = I18N :: translate ( 'User verification' ) ; $ user = $ user_service -> findByUserName ( $ username ) ; if ( $ user instanceof User && $ user -> getPreference ( 'reg_hashcode' ) === $ token ) { $ webmaster = $ user_service -> find ( ( int ) $ tree -> getPreference ( 'WEBMASTER_USER_ID' ) ) ; if ( $ webmaster instanceof User ) { I18N :: init ( $ webmaster -> getPreference ( 'language' ) ) ; $ subject = I18N :: translate ( 'New user at %s' , WT_BASE_URL . ' ' . $ tree -> title ( ) ) ; Mail :: send ( new TreeUser ( $ tree ) , $ webmaster , new TreeUser ( $ tree ) , $ subject , view ( 'emails/verify-notify-text' , [ 'user' => $ user ] ) , view ( 'emails/verify-notify-html' , [ 'user' => $ user ] ) ) ; $ mail1_method = $ webmaster -> getPreference ( 'CONTACT_METHOD' ) ; if ( $ mail1_method !== 'messaging3' && $ mail1_method !== 'mailto' && $ mail1_method !== 'none' ) { DB :: table ( 'message' ) -> insert ( [ 'sender' => $ username , 'ip_address' => $ request -> getClientIp ( ) , 'user_id' => $ webmaster -> id ( ) , 'subject' => $ subject , 'body' => view ( 'emails/verify-notify-text' , [ 'user' => $ user ] ) , ] ) ; } I18N :: init ( WT_LOCALE ) ; } $ user -> setPreference ( 'verified' , '1' ) -> setPreference ( 'reg_timestamp' , date ( 'U' ) ) -> setPreference ( 'reg_hashcode' , '' ) ; Log :: addAuthenticationLog ( 'User ' . $ username . ' verified their email address' ) ; return $ this -> viewResponse ( 'verify-success-page' , [ 'title' => $ title , ] ) ; } return $ this -> viewResponse ( 'verify-failure-page' , [ 'title' => $ title , ] ) ; }
Respond to a verification link that was emailed to a user .
7,381
private function findMediaObjectsForMediaFile ( string $ file ) : array { return DB :: table ( 'media' ) -> join ( 'media_file' , static function ( JoinClause $ join ) : void { $ join -> on ( 'media_file.m_file' , '=' , 'media.m_file' ) -> on ( 'media_file.m_id' , '=' , 'media.m_id' ) ; } ) -> join ( 'gedcom_setting' , 'media.m_file' , '=' , 'gedcom_setting.gedcom_id' ) -> where ( DB :: raw ( 'setting_value || multimedia_file_refn' ) , '=' , $ file ) -> select ( [ 'media.*' ] ) -> distinct ( ) -> get ( ) -> map ( Media :: rowMapper ( ) ) -> all ( ) ; }
Find the media object that uses a particular media file .
7,382
private function scaledImagePixels ( $ path ) : array { $ size = 10 ; $ sha1 = sha1_file ( $ path ) ; $ cache_file = WT_DATA_DIR . 'cache/' . $ sha1 . '.php' ; if ( file_exists ( $ cache_file ) ) { return include $ cache_file ; } $ manager = new ImageManager ( ) ; $ image = $ manager -> make ( $ path ) -> resize ( $ size , $ size ) ; $ pixels = [ ] ; for ( $ x = 0 ; $ x < $ size ; ++ $ x ) { $ pixels [ $ x ] = [ ] ; for ( $ y = 0 ; $ y < $ size ; ++ $ y ) { $ pixel = $ image -> pickColor ( $ x , $ y ) ; $ pixels [ $ x ] [ $ y ] = ( int ) ( ( $ pixel [ 0 ] + $ pixel [ 1 ] + $ pixel [ 2 ] ) / 3 ) ; } } file_put_contents ( $ cache_file , '<?php return ' . var_export ( $ pixels , true ) . ';' ) ; return $ pixels ; }
Scale an image to 10x10 and read the individual pixels . This is a slow operation add we will do it many times on the import wetbrees 1 thumbnails page so cache the results .
7,383
public function header ( ) { foreach ( $ this -> headerElements as $ element ) { if ( $ element instanceof ReportBaseElement ) { $ element -> render ( $ this ) ; } elseif ( $ element === 'footnotetexts' ) { $ this -> footnotes ( ) ; } elseif ( $ element === 'addpage' ) { $ this -> newPage ( ) ; } } foreach ( $ this -> pageHeaderElements as $ element ) { if ( $ element instanceof ReportBaseElement ) { $ element -> render ( $ this ) ; } elseif ( $ element === 'footnotetexts' ) { $ this -> footnotes ( ) ; } elseif ( $ element === 'addpage' ) { $ this -> newPage ( ) ; } } }
PDF Header - PDF
7,384
public function body ( ) { $ this -> AddPage ( ) ; foreach ( $ this -> bodyElements as $ key => $ element ) { if ( $ element instanceof ReportBaseElement ) { $ element -> render ( $ this ) ; } elseif ( $ element === 'footnotetexts' ) { $ this -> footnotes ( ) ; } elseif ( $ element === 'addpage' ) { $ this -> newPage ( ) ; } } }
PDF Body - PDF
7,385
public function footnotes ( ) { foreach ( $ this -> printedfootnotes as $ element ) { if ( ( $ this -> GetY ( ) + $ element -> getFootnoteHeight ( $ this ) ) > $ this -> getPageHeight ( ) ) { $ this -> AddPage ( ) ; } $ element -> renderFootnote ( $ this ) ; if ( $ this -> GetY ( ) > $ this -> getPageHeight ( ) ) { $ this -> AddPage ( ) ; } } }
PDF Footnotes - PDF
7,386
public function footer ( ) { foreach ( $ this -> footerElements as $ element ) { if ( $ element instanceof ReportBaseElement ) { $ element -> render ( $ this ) ; } elseif ( $ element === 'footnotetexts' ) { $ this -> footnotes ( ) ; } elseif ( $ element === 'addpage' ) { $ this -> newPage ( ) ; } } }
PDF Footer - PDF
7,387
public function setCurrentStyle ( string $ s ) { $ this -> currentStyle = $ s ; $ style = $ this -> wt_report -> getStyle ( $ s ) ; $ this -> SetFont ( $ style [ 'font' ] , $ style [ 'style' ] , $ style [ 'size' ] ) ; }
Setup a style for usage - PDF
7,388
public function getStyle ( string $ s ) : array { if ( ! isset ( $ this -> wt_report -> styles [ $ s ] ) ) { $ s = $ this -> getCurrentStyle ( ) ; $ this -> wt_report -> styles [ $ s ] = $ s ; } return $ this -> wt_report -> styles [ $ s ] ; }
Get the style - PDF
7,389
public function addMarginX ( float $ x ) : float { $ m = $ this -> getMargins ( ) ; if ( $ this -> getRTL ( ) ) { $ x += $ m [ 'right' ] ; } else { $ x += $ m [ 'left' ] ; } $ this -> SetX ( $ x ) ; return $ x ; }
Add margin when static horizontal position is used - PDF RTL supported
7,390
public function getMaxLineWidth ( ) { $ m = $ this -> getMargins ( ) ; if ( $ this -> getRTL ( ) ) { return ( $ this -> getRemainingWidth ( ) + $ m [ 'right' ] ) ; } return ( $ this -> getRemainingWidth ( ) + $ m [ 'left' ] ) ; }
Get the maximum line width to draw from the curren position - PDF RTL supported
7,391
public function getFootnotesHeight ( ) : float { $ h = 0 ; foreach ( $ this -> printedfootnotes as $ element ) { $ h += $ element -> getHeight ( $ this ) ; } return $ h ; }
Get the height of the footnote .
7,392
protected function formatLongYear ( ) : string { if ( $ this -> year < 0 ) { return I18N :: translate ( '%s&nbsp;BCE' , I18N :: digits ( - $ this -> year ) ) ; } if ( $ this -> new_old_style ) { return I18N :: translate ( '%s&nbsp;CE' , I18N :: digits ( sprintf ( '%d/%02d' , $ this -> year - 1 , $ this -> year % 100 ) ) ) ; } return I18N :: translate ( '%s&nbsp;CE' , I18N :: digits ( $ this -> year ) ) ; }
Generate the %Y format for a date .
7,393
protected function formatGedcomYear ( ) : string { if ( $ this -> year < 0 ) { return sprintf ( '%04d B.C.' , - $ this -> year ) ; } if ( $ this -> new_old_style ) { return sprintf ( '%04d/%02d' , $ this -> year - 1 , $ this -> year % 100 ) ; } return sprintf ( '%04d' , $ this -> year ) ; }
Generate the %E format for a date .
7,394
public function folder ( ServerRequestInterface $ request , Tree $ tree , Filesystem $ filesystem ) : ResponseInterface { $ query = $ request -> get ( 'query' , '' ) ; $ prefix = $ tree -> getPreference ( 'MEDIA_DIRECTORY' , '' ) ; $ media_filesystem = new Filesystem ( new ChrootAdapter ( $ filesystem , $ prefix ) ) ; $ contents = new Collection ( $ media_filesystem -> listContents ( '' , true ) ) ; $ folders = $ contents -> filter ( static function ( array $ object ) use ( $ query ) : bool { return $ object [ 'type' ] === 'dir' && Str :: contains ( $ object [ 'path' ] , $ query ) ; } ) -> map ( static function ( array $ object ) : array { return [ 'value' => $ object [ 'path' ] ] ; } ) ; return response ( $ folders ) ; }
Autocomplete for media folders .
7,395
public function page ( ServerRequestInterface $ request , Tree $ tree ) : ResponseInterface { $ query = $ request -> get ( 'query' , '' ) ; $ xref = $ request -> get ( 'extra' , '' ) ; $ source = Source :: getInstance ( $ xref , $ tree ) ; Auth :: checkSourceAccess ( $ source ) ; $ regex_query = preg_quote ( strtr ( $ query , [ ' ' => '.+' ] ) , '/' ) ; $ individuals = DB :: table ( 'individuals' ) -> join ( 'link' , static function ( JoinClause $ join ) : void { $ join -> on ( 'l_file' , '=' , 'i_file' ) -> on ( 'l_from' , '=' , 'i_id' ) ; } ) -> where ( 'i_file' , '=' , $ tree -> id ( ) ) -> where ( 'l_to' , '=' , $ xref ) -> where ( 'l_type' , '=' , 'SOUR' ) -> distinct ( ) -> select ( [ 'individuals.*' ] ) -> get ( ) -> map ( Individual :: rowMapper ( ) ) -> filter ( GedcomRecord :: accessFilter ( ) ) ; $ families = DB :: table ( 'families' ) -> join ( 'link' , static function ( JoinClause $ join ) : void { $ join -> on ( 'l_file' , '=' , 'f_file' ) -> on ( 'l_from' , '=' , 'f_id' ) -> where ( 'l_type' , '=' , 'SOUR' ) ; } ) -> where ( 'f_file' , '=' , $ tree -> id ( ) ) -> where ( 'l_to' , '=' , $ xref ) -> where ( 'l_type' , '=' , 'SOUR' ) -> distinct ( ) -> select ( [ 'families.*' ] ) -> get ( ) -> map ( Family :: rowMapper ( ) ) -> filter ( GedcomRecord :: accessFilter ( ) ) ; $ pages = [ ] ; foreach ( $ individuals -> merge ( $ families ) as $ record ) { if ( preg_match_all ( '/\n1 SOUR @' . $ xref . '@(?:\n[2-9].*)*\n2 PAGE (.*' . $ regex_query . '.*)/i' , $ record -> gedcom ( ) , $ matches ) ) { $ pages = array_merge ( $ pages , $ matches [ 1 ] ) ; } if ( preg_match_all ( '/\n2 SOUR @' . $ xref . '@(?:\n[3-9].*)*\n3 PAGE (.*' . $ regex_query . '.*)/i' , $ record -> gedcom ( ) , $ matches ) ) { $ pages = array_merge ( $ pages , $ matches [ 1 ] ) ; } } $ pages = array_unique ( $ pages ) ; $ pages = array_map ( static function ( string $ page ) : array { return [ 'value' => $ page ] ; } , $ pages ) ; return response ( $ pages ) ; }
Autocomplete for source citations .
7,396
private function placeSearch ( Tree $ tree , int $ page , string $ query , bool $ create ) : array { $ offset = $ page * self :: RESULTS_PER_PAGE ; $ results = [ ] ; $ found = false ; foreach ( $ this -> search_service -> searchPlaces ( $ tree , $ query ) as $ place ) { $ place_name = $ place -> gedcomName ( ) ; if ( $ place_name === $ query ) { $ found = true ; } $ results [ ] = [ 'id' => $ place_name , 'text' => $ place_name , 'title' => ' ' , ] ; } if ( empty ( $ results ) && $ tree -> getPreference ( 'GEONAMES_ACCOUNT' ) ) { $ url = 'http://api.geonames.org/searchJSON' . '?name_startsWith=' . urlencode ( $ query ) . '&lang=' . WT_LOCALE . '&fcode=CMTY&fcode=ADM4&fcode=PPL&fcode=PPLA&fcode=PPLC' . '&style=full' . '&username=' . $ tree -> getPreference ( 'GEONAMES_ACCOUNT' ) ; if ( ini_get ( 'allow_url_fopen' ) ) { $ json = file_get_contents ( $ url ) ; $ places = json_decode ( $ json , true ) ; } elseif ( function_exists ( 'curl_init' ) ) { $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; $ json = curl_exec ( $ ch ) ; $ places = json_decode ( $ json , true ) ; curl_close ( $ ch ) ; } else { $ places = [ ] ; } if ( isset ( $ places [ 'geonames' ] ) && is_array ( $ places [ 'geonames' ] ) ) { foreach ( $ places [ 'geonames' ] as $ k => $ place ) { $ place_name = $ place [ 'name' ] . ', ' . $ place [ 'adminName2' ] . ', ' . $ place [ 'adminName1' ] . ', ' . $ place [ 'countryName' ] ; if ( $ place_name === $ query ) { $ found = true ; } $ results [ ] = [ 'id' => $ place_name , 'text' => $ place_name , 'title' => ' ' , ] ; } } } if ( ! $ found && $ create ) { array_unshift ( $ results , [ 'id' => $ query , 'text' => $ query , ] ) ; } $ more = count ( $ results ) > $ offset + self :: RESULTS_PER_PAGE ; $ results = array_slice ( $ results , $ offset , self :: RESULTS_PER_PAGE ) ; return [ 'results' => $ results , 'pagination' => [ 'more' => $ more , ] , ] ; }
Look up a place name .
7,397
public function getSidebarContent ( Individual $ individual ) : string { ob_start ( ) ; foreach ( $ individual -> facts ( static :: HANDLED_FACTS ) as $ fact ) { FunctionsPrintFacts :: printFact ( $ fact , $ individual ) ; } $ html = ob_get_clean ( ) ; return strip_tags ( $ html , '<a><div><span>' ) ; }
Load this sidebar synchronously .
7,398
private function surnamesToAdd ( GedcomRecord $ record ) : array { $ gedcom = $ record -> gedcom ( ) ; $ tree = $ record -> tree ( ) ; $ wife_surnames = $ this -> surnames ( $ record ) ; $ husb_surnames = [ ] ; $ missing_surnames = [ ] ; preg_match_all ( '/^1 FAMS @(.+)@/m' , $ gedcom , $ fmatch ) ; foreach ( $ fmatch [ 1 ] as $ famid ) { $ family = Family :: getInstance ( $ famid , $ tree ) ; $ famrec = $ family -> gedcom ( ) ; if ( preg_match ( '/^1 MARR/m' , $ famrec ) && preg_match ( '/^1 HUSB @(.+)@/m' , $ famrec , $ hmatch ) ) { $ spouse = Individual :: getInstance ( $ hmatch [ 1 ] , $ tree ) ; if ( $ spouse instanceof Individual ) { $ husb_surnames = array_unique ( array_merge ( $ husb_surnames , $ this -> surnames ( $ spouse ) ) ) ; } } } foreach ( $ husb_surnames as $ husb_surname ) { if ( ! in_array ( $ husb_surname , $ wife_surnames , true ) ) { $ missing_surnames [ ] = $ husb_surname ; } } return $ missing_surnames ; }
Generate a list of married surnames that are not already present .
7,399
private function surnames ( GedcomRecord $ record ) : array { $ gedcom = $ record -> gedcom ( ) ; if ( preg_match_all ( '/^(?:1 NAME|2 _MARNM) .*\/(.+)\//m' , $ gedcom , $ match ) ) { return $ match [ 1 ] ; } return [ ] ; }
Extract a list of surnames from a GEDCOM record .