idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
7,400
|
public function fixLevel0MediaAction ( ServerRequestInterface $ request ) : ResponseInterface { $ fact_id = $ request -> getParsedBody ( ) [ 'fact_id' ] ; $ indi_xref = $ request -> getParsedBody ( ) [ 'indi_xref' ] ; $ obje_xref = $ request -> getParsedBody ( ) [ 'obje_xref' ] ; $ tree_id = ( int ) $ request -> getParsedBody ( ) [ 'tree_id' ] ; $ tree = Tree :: findById ( $ tree_id ) ; $ individual = Individual :: getInstance ( $ indi_xref , $ tree ) ; $ media = Media :: getInstance ( $ obje_xref , $ tree ) ; if ( $ individual !== null && $ media !== null ) { foreach ( $ individual -> facts ( ) as $ fact1 ) { if ( $ fact1 -> id ( ) === $ fact_id ) { $ individual -> updateFact ( $ fact_id , $ fact1 -> gedcom ( ) . "\n2 OBJE @" . $ obje_xref . '@' , false ) ; foreach ( $ individual -> facts ( [ 'OBJE' ] ) as $ fact2 ) { if ( $ fact2 -> target ( ) === $ media ) { $ individual -> deleteFact ( $ fact2 -> id ( ) , false ) ; } } break ; } } } return response ( ) ; }
|
Move a link to a media object from a level 0 record to a level 1 record .
|
7,401
|
private function getSosaName ( int $ sosa ) : string { $ path = '' ; while ( $ sosa > 1 ) { if ( $ sosa % 2 === 1 ) { $ path = 'mot' . $ path ; } else { $ path = 'fat' . $ path ; } $ sosa = intdiv ( $ sosa , 2 ) ; } return Functions :: getRelationshipNameFromPath ( $ path ) ; }
|
builds and returns sosa relationship name in the active language
|
7,402
|
public static function printFactNotes ( Tree $ tree , $ factrec , $ level ) : string { $ data = '' ; $ previous_spos = 0 ; $ nlevel = $ level + 1 ; $ ct = preg_match_all ( "/$level NOTE (.*)/" , $ factrec , $ match , PREG_SET_ORDER ) ; for ( $ j = 0 ; $ j < $ ct ; $ j ++ ) { $ spos1 = strpos ( $ factrec , $ match [ $ j ] [ 0 ] , $ previous_spos ) ; $ spos2 = strpos ( $ factrec . "\n$level" , "\n$level" , $ spos1 + 1 ) ; if ( ! $ spos2 ) { $ spos2 = strlen ( $ factrec ) ; } $ previous_spos = $ spos2 ; $ nrec = substr ( $ factrec , $ spos1 , $ spos2 - $ spos1 ) ; if ( ! isset ( $ match [ $ j ] [ 1 ] ) ) { $ match [ $ j ] [ 1 ] = '' ; } if ( ! preg_match ( '/^@(' . Gedcom :: REGEX_XREF . ')@$/' , $ match [ $ j ] [ 1 ] , $ nmatch ) ) { $ data .= self :: printNoteRecord ( $ tree , $ match [ $ j ] [ 1 ] , $ nlevel , $ nrec ) ; } else { $ note = Note :: getInstance ( $ nmatch [ 1 ] , $ tree ) ; if ( $ note ) { if ( $ note -> canShow ( ) ) { $ noterec = $ note -> gedcom ( ) ; $ nt = preg_match ( "/0 @$nmatch[1]@ NOTE (.*)/" , $ noterec , $ n1match ) ; $ data .= self :: printNoteRecord ( $ tree , ( $ nt > 0 ) ? $ n1match [ 1 ] : '' , 1 , $ noterec ) ; } } else { $ data = '<div class="fact_NOTE"><span class="label">' . I18N :: translate ( 'Note' ) . '</span>: <span class="field error">' . $ nmatch [ 1 ] . '</span></div>' ; } } } return $ data ; }
|
Print all of the notes in this fact record
|
7,403
|
public static function helpLink ( $ topic ) : string { return '<a href="#" data-toggle="modal" data-target="#wt-ajax-modal" data-href="' . e ( route ( 'help-text' , [ 'topic' => $ topic ] ) ) . '" title="' . I18N :: translate ( 'Help' ) . '">' . view ( 'icons/help' ) . '<span class="sr-only">' . I18N :: translate ( 'Help' ) . '</span>' . '</a>' ; }
|
Print a link for a popup help window .
|
7,404
|
public static function checkFactUnique ( array $ uniquefacts , Collection $ recfacts ) : array { foreach ( $ recfacts as $ factarray ) { $ fact = $ factarray -> getTag ( ) ; $ key = array_search ( $ fact , $ uniquefacts , true ) ; if ( $ key !== false ) { unset ( $ uniquefacts [ $ key ] ) ; } } return $ uniquefacts ; }
|
Check for facts that may exist only once for a certain record type . If the fact already exists in the second array delete it from the first one .
|
7,405
|
private function themes ( ) : Generator { $ themes = $ this -> module_service -> findByInterface ( ModuleThemeInterface :: class ) ; yield $ themes -> get ( Session :: get ( 'theme' , '' ) ) ; $ tree = app ( Tree :: class ) ; if ( $ tree instanceof Tree ) { yield $ themes -> get ( $ tree -> getPreference ( 'THEME_DIR' ) ) ; } yield $ themes -> get ( Site :: getPreference ( 'THEME_DIR' ) ) ; yield app ( WebtreesTheme :: class ) ; }
|
The theme can be chosen in various ways .
|
7,406
|
public function updateSchema ( $ namespace , $ schema_name , $ target_version ) : bool { try { $ current_version = ( int ) Site :: getPreference ( $ schema_name ) ; } catch ( PDOException $ ex ) { $ current_version = 0 ; } $ updates_applied = false ; while ( $ current_version < $ target_version ) { $ class = $ namespace . '\\Migration' . $ current_version ; $ migration = new $ class ( ) ; $ migration -> upgrade ( ) ; $ current_version ++ ; Site :: setPreference ( $ schema_name , ( string ) $ current_version ) ; $ updates_applied = true ; } return $ updates_applied ; }
|
Run a series of scripts to bring the database schema up to date .
|
7,407
|
public function seedDatabase ( ) : void { ( new SeedSiteSettingTable ( ) ) -> run ( ) ; ( new SeedUserTable ( ) ) -> run ( ) ; ( new SeedGedcomTable ( ) ) -> run ( ) ; ( new SeedGedcomSettingTable ( ) ) -> run ( ) ; ( new SeedDefaultResnTable ( ) ) -> run ( ) ; }
|
Write default data to the database .
|
7,408
|
public function dispatch ( $ object , string $ method ) { $ reflector = new ReflectionMethod ( $ object , $ method ) ; $ parameters = $ this -> makeParameters ( $ reflector -> getParameters ( ) ) ; return $ reflector -> invoke ( $ object , ... $ parameters ) ; }
|
Call an object s method injecting all its dependencies .
|
7,409
|
public function fileSizeKB ( ) : string { $ size = $ this -> fileSizeBytes ( ) ; $ size = intdiv ( $ size + 1023 , 1024 ) ; return I18N :: translate ( '%s KB' , I18N :: number ( $ size ) ) ; }
|
get the media file size in KB
|
7,410
|
public function downloadUrl ( ) : string { return route ( 'media-download' , [ 'xref' => $ this -> media -> xref ( ) , 'ged' => $ this -> media -> tree ( ) -> name ( ) , 'fact_id' => $ this -> fact_id , ] ) ; }
|
Generate a URL to download a non - image media file .
|
7,411
|
public function imageUrl ( $ width , $ height , $ fit ) : string { $ glide_key = Site :: getPreference ( 'glide-key' ) ; if ( empty ( $ glide_key ) ) { $ glide_key = bin2hex ( random_bytes ( 128 ) ) ; Site :: setPreference ( 'glide-key' , $ glide_key ) ; } if ( Auth :: accessLevel ( $ this -> media -> tree ( ) ) > $ this -> media -> tree ( ) -> getPreference ( 'SHOW_NO_WATERMARK' ) ) { $ mark = 'watermark.png' ; } else { $ mark = '' ; } $ url_builder = UrlBuilderFactory :: create ( WT_BASE_URL , $ glide_key ) ; $ url = $ url_builder -> getUrl ( 'index.php' , [ 'route' => 'media-thumbnail' , 'xref' => $ this -> media -> xref ( ) , 'ged' => $ this -> media -> tree ( ) -> name ( ) , 'fact_id' => $ this -> fact_id , 'w' => $ width , 'h' => $ height , 'fit' => $ fit , 'mark' => $ mark , 'markh' => '100h' , 'markw' => '100w' , 'markalpha' => 25 , 'or' => 0 , ] ) ; return $ url ; }
|
Generate a URL for an image .
|
7,412
|
public function getAllTagsTable ( ) : string { $ examples = [ ] ; foreach ( get_class_methods ( $ this ) as $ method ) { $ reflection = new ReflectionMethod ( $ this , $ method ) ; if ( $ reflection -> isPublic ( ) && ! in_array ( $ method , self :: $ public_but_not_allowed , true ) && ( string ) $ reflection -> getReturnType ( ) !== Builder :: class ) { $ examples [ $ method ] = $ this -> $ method ( ) ; } } ksort ( $ examples ) ; $ html = '' ; foreach ( $ examples as $ tag => $ value ) { $ html .= '<dt>#' . $ tag . '#</dt>' ; $ html .= '<dd>' . $ value . '</dd>' ; } return '<dl>' . $ html . '</dl>' ; }
|
Return a string of all supported tags and an example of its output in table row form .
|
7,413
|
public function getAllTagsText ( ) : string { $ examples = [ ] ; foreach ( get_class_methods ( $ this ) as $ method ) { $ reflection = new ReflectionMethod ( $ this , $ method ) ; if ( $ reflection -> isPublic ( ) && ! in_array ( $ method , self :: $ public_but_not_allowed , true ) && ( string ) $ reflection -> getReturnType ( ) !== Builder :: class ) { $ examples [ $ method ] = $ method ; } } ksort ( $ examples ) ; return implode ( '<br>' , $ examples ) ; }
|
Return a string of all supported tags in plain text .
|
7,414
|
private function getTags ( string $ text ) : array { $ tags = [ ] ; $ matches = [ ] ; preg_match_all ( '/#([^#]+)#/' , $ text , $ matches , PREG_SET_ORDER ) ; foreach ( $ matches as $ match ) { $ params = explode ( ':' , $ match [ 1 ] ) ; $ method = array_shift ( $ params ) ; if ( method_exists ( $ this , $ method ) ) { $ tags [ $ match [ 0 ] ] = $ this -> $ method ( ... $ params ) ; } } return $ tags ; }
|
Get tags and their parsed results .
|
7,415
|
public function embedTags ( string $ text ) : string { if ( strpos ( $ text , '#' ) !== false ) { $ text = strtr ( $ text , $ this -> getTags ( $ text ) ) ; } return $ text ; }
|
Embed tags in text
|
7,416
|
private function getRecentChanges ( Tree $ tree , int $ days ) : array { return DB :: table ( 'change' ) -> where ( 'gedcom_id' , '=' , $ tree -> id ( ) ) -> where ( 'status' , '=' , 'accepted' ) -> where ( 'new_gedcom' , '<>' , '' ) -> where ( 'change_time' , '>' , Carbon :: now ( ) -> subDays ( $ days ) ) -> groupBy ( 'xref' ) -> pluck ( 'xref' ) -> map ( static function ( string $ xref ) use ( $ tree ) : ? GedcomRecord { return GedcomRecord :: getInstance ( $ xref , $ tree ) ; } ) -> filter ( static function ( ? GedcomRecord $ record ) : bool { return $ record instanceof GedcomRecord && $ record -> canShow ( ) ; } ) -> all ( ) ; }
|
Find records that have changed since a given julian day
|
7,417
|
private function formatDates ( array $ gedcom_dates ) : array { $ dates = [ ] ; foreach ( $ gedcom_dates as $ gedcom_date ) { $ gedcom_date = ( string ) $ gedcom_date ; $ date = new Date ( $ gedcom_date ) ; $ dates [ $ gedcom_date ] = strip_tags ( $ date -> display ( false , null , false ) ) ; } return $ dates ; }
|
Format GEDCOM dates in the local language .
|
7,418
|
public function postDeleteMessageAction ( ServerRequestInterface $ request , Tree $ tree ) : ResponseInterface { $ message_ids = ( array ) $ request -> get ( 'message_id' , [ ] ) ; DB :: table ( 'message' ) -> where ( 'user_id' , '=' , Auth :: id ( ) ) -> whereIn ( 'message_id' , $ message_ids ) -> delete ( ) ; if ( $ request -> get ( 'ctype' ) === 'user' ) { $ url = route ( 'user-page' , [ 'ged' => $ tree -> name ( ) ] ) ; } else { $ url = route ( 'tree-page' , [ 'ged' => $ tree -> name ( ) ] ) ; } return redirect ( $ url ) ; }
|
Delete one or messages belonging to a user .
|
7,419
|
private function getMedia ( Individual $ individual ) : array { if ( $ this -> media_list === null ) { $ facts = $ individual -> facts ( ) ; foreach ( $ individual -> spouseFamilies ( ) as $ family ) { foreach ( $ family -> facts ( ) as $ fact ) { $ facts -> push ( $ fact ) ; } } $ this -> media_list = [ ] ; foreach ( $ facts as $ fact ) { if ( ! $ fact -> isPendingDeletion ( ) ) { preg_match_all ( '/(?:^1|\n\d) OBJE @(' . Gedcom :: REGEX_XREF . ')@/' , $ fact -> gedcom ( ) , $ matches ) ; foreach ( $ matches [ 1 ] as $ match ) { $ media = Media :: getInstance ( $ match , $ individual -> tree ( ) ) ; if ( $ media && $ media -> canShow ( ) ) { $ this -> media_list [ ] = $ media ; } } } } $ this -> media_list = array_unique ( $ this -> media_list ) ; $ wt_obje_sort = [ ] ; foreach ( $ individual -> facts ( [ '_WT_OBJE_SORT' ] ) as $ fact ) { $ wt_obje_sort [ ] = trim ( $ fact -> value ( ) , '@' ) ; } usort ( $ this -> media_list , static function ( Media $ x , Media $ y ) use ( $ wt_obje_sort ) : int { return array_search ( $ x -> xref ( ) , $ wt_obje_sort , true ) - array_search ( $ y -> xref ( ) , $ wt_obje_sort , true ) ; } ) ; } return $ this -> media_list ; }
|
Get all facts containing media links for this person and their spouse - family records
|
7,420
|
private function axisMonths ( ) : array { return [ 'JAN' => I18N :: translateContext ( 'NOMINATIVE' , 'January' ) , 'FEB' => I18N :: translateContext ( 'NOMINATIVE' , 'February' ) , 'MAR' => I18N :: translateContext ( 'NOMINATIVE' , 'March' ) , 'APR' => I18N :: translateContext ( 'NOMINATIVE' , 'April' ) , 'MAY' => I18N :: translateContext ( 'NOMINATIVE' , 'May' ) , 'JUN' => I18N :: translateContext ( 'NOMINATIVE' , 'June' ) , 'JUL' => I18N :: translateContext ( 'NOMINATIVE' , 'July' ) , 'AUG' => I18N :: translateContext ( 'NOMINATIVE' , 'August' ) , 'SEP' => I18N :: translateContext ( 'NOMINATIVE' , 'September' ) , 'OCT' => I18N :: translateContext ( 'NOMINATIVE' , 'October' ) , 'NOV' => I18N :: translateContext ( 'NOMINATIVE' , 'November' ) , 'DEC' => I18N :: translateContext ( 'NOMINATIVE' , 'December' ) , ] ; }
|
Labels for the X axis
|
7,421
|
private function axisYears ( string $ boundaries_csv ) : array { $ boundaries = explode ( ',' , $ boundaries_csv ) ; $ axis = [ ] ; foreach ( $ boundaries as $ n => $ boundary ) { if ( $ n === 0 ) { $ date = new Date ( 'BEF ' . $ boundary ) ; } else { $ date = new Date ( 'BET ' . $ boundaries [ $ n - 1 ] . ' AND ' . ( $ boundary - 1 ) ) ; } $ axis [ $ boundary - 1 ] = strip_tags ( $ date -> display ( ) ) ; } $ date = new Date ( 'AFT ' . $ boundaries [ count ( $ boundaries ) - 1 ] ) ; $ axis [ PHP_INT_MAX ] = strip_tags ( $ date -> display ( ) ) ; return $ axis ; }
|
Convert a list of N year - boundaries into N + 1 year - ranges for the z - axis .
|
7,422
|
private function fillYData ( $ x , $ z , $ value , array $ x_axis , array $ z_axis , array & $ ydata ) : void { $ x = $ this -> findAxisEntry ( $ x , $ x_axis ) ; $ z = $ this -> findAxisEntry ( $ z , $ z_axis ) ; if ( ! array_key_exists ( $ z , $ z_axis ) ) { foreach ( array_keys ( $ z_axis ) as $ key ) { if ( $ value <= $ key ) { $ z = $ key ; break ; } } } $ ydata [ $ z ] [ $ x ] = ( $ ydata [ $ z ] [ $ x ] ?? 0 ) + $ value ; }
|
Calculate the Y axis .
|
7,423
|
private function myPlot ( string $ chart_title , array $ x_axis , string $ x_axis_title , array $ ydata , string $ y_axis_title , array $ z_axis , int $ y_axis_type ) : string { if ( ! count ( $ ydata ) ) { return I18N :: translate ( 'This information is not available.' ) ; } $ colors = [ ] ; $ index = 0 ; while ( count ( $ colors ) < count ( $ ydata ) ) { $ colors [ ] = self :: Z_AXIS_COLORS [ $ index ] ; $ index = ( $ index + 1 ) % count ( self :: Z_AXIS_COLORS ) ; } $ tmp = [ ] ; foreach ( array_keys ( $ z_axis ) as $ z ) { foreach ( array_keys ( $ x_axis ) as $ x ) { $ tmp [ $ z ] [ $ x ] = $ ydata [ $ z ] [ $ x ] ?? 0 ; } } $ ydata = $ tmp ; if ( $ y_axis_type === self :: Y_AXIS_PERCENT ) { array_walk ( $ ydata , static function ( array & $ x ) { $ sum = array_sum ( $ x ) ; if ( $ sum > 0 ) { $ x = array_map ( static function ( $ y ) use ( $ sum ) { return $ y * 100.0 / $ sum ; } , $ x ) ; } } ) ; } $ data = [ array_merge ( [ I18N :: translate ( 'Century' ) ] , array_values ( $ z_axis ) ) ] ; $ intermediate = [ ] ; foreach ( $ ydata as $ century => $ months ) { foreach ( $ months as $ month => $ value ) { $ intermediate [ $ month ] [ ] = [ 'v' => $ value , 'f' => ( $ y_axis_type === self :: Y_AXIS_PERCENT ) ? sprintf ( '%.1f%%' , $ value ) : $ value , ] ; } } foreach ( $ intermediate as $ key => $ values ) { $ data [ ] = array_merge ( [ $ x_axis [ $ key ] ] , $ values ) ; } $ chart_options = [ 'title' => '' , 'subtitle' => '' , 'height' => 400 , 'width' => '100%' , 'legend' => [ 'position' => count ( $ z_axis ) > 1 ? 'right' : 'none' , 'alignment' => 'center' , ] , 'tooltip' => [ 'format' => '\'%\'' , ] , 'vAxis' => [ 'title' => $ y_axis_title ?? '' , ] , 'hAxis' => [ 'title' => $ x_axis_title ?? '' , ] , 'colors' => $ colors , ] ; return view ( 'statistics/other/charts/custom' , [ 'data' => $ data , 'chart_options' => $ chart_options , 'chart_title' => $ chart_title , ] ) ; }
|
Plot the data .
|
7,424
|
public static function updatePlaces ( string $ xref , Tree $ tree , string $ gedrec ) : void { preg_match_all ( '/^[2-9] PLAC (.+)/m' , $ gedrec , $ matches ) ; $ places = array_unique ( $ matches [ 1 ] ) ; foreach ( $ places as $ place_name ) { $ place = new Place ( $ place_name , $ tree ) ; while ( $ place -> id ( ) !== 0 ) { try { DB :: table ( 'placelinks' ) -> insert ( [ 'pl_p_id' => $ place -> id ( ) , 'pl_gid' => $ xref , 'pl_file' => $ tree -> id ( ) , ] ) ; } catch ( PDOException $ ex ) { break ; } $ place = $ place -> parent ( ) ; } } }
|
Extract all level 2 places from the given record and insert them into the places table
|
7,425
|
public static function updateDates ( $ xref , $ ged_id , $ gedrec ) : void { if ( strpos ( $ gedrec , '2 DATE ' ) && preg_match_all ( "/\n1 (\w+).*(?:\n[2-9].*)*(?:\n2 DATE (.+))(?:\n[2-9].*)*/" , $ gedrec , $ matches , PREG_SET_ORDER ) ) { foreach ( $ matches as $ match ) { $ fact = $ match [ 1 ] ; if ( ( $ fact === 'FACT' || $ fact === 'EVEN' ) && preg_match ( "/\n2 TYPE ([A-Z]{3,5})/" , $ match [ 0 ] , $ tmatch ) ) { $ fact = $ tmatch [ 1 ] ; } $ date = new Date ( $ match [ 2 ] ) ; DB :: table ( 'dates' ) -> insert ( [ 'd_day' => $ date -> minimumDate ( ) -> day , 'd_month' => $ date -> minimumDate ( ) -> format ( '%O' ) , 'd_mon' => $ date -> minimumDate ( ) -> month , 'd_year' => $ date -> minimumDate ( ) -> year , 'd_julianday1' => $ date -> minimumDate ( ) -> minimumJulianDay ( ) , 'd_julianday2' => $ date -> minimumDate ( ) -> maximumJulianDay ( ) , 'd_fact' => $ fact , 'd_gid' => $ xref , 'd_file' => $ ged_id , 'd_type' => $ date -> minimumDate ( ) -> format ( '%@' ) , ] ) ; if ( $ date -> minimumDate ( ) !== $ date -> maximumDate ( ) ) { DB :: table ( 'dates' ) -> insert ( [ 'd_day' => $ date -> maximumDate ( ) -> day , 'd_month' => $ date -> maximumDate ( ) -> format ( '%O' ) , 'd_mon' => $ date -> maximumDate ( ) -> month , 'd_year' => $ date -> maximumDate ( ) -> year , 'd_julianday1' => $ date -> maximumDate ( ) -> minimumJulianDay ( ) , 'd_julianday2' => $ date -> maximumDate ( ) -> maximumJulianDay ( ) , 'd_fact' => $ fact , 'd_gid' => $ xref , 'd_file' => $ ged_id , 'd_type' => $ date -> minimumDate ( ) -> format ( '%@' ) , ] ) ; } } } }
|
Extract all the dates from the given record and insert them into the database .
|
7,426
|
public static function updateLinks ( $ xref , $ ged_id , $ gedrec ) : void { if ( preg_match_all ( '/^\d+ (' . Gedcom :: REGEX_TAG . ') @(' . Gedcom :: REGEX_XREF . ')@/m' , $ gedrec , $ matches , PREG_SET_ORDER ) ) { $ data = [ ] ; foreach ( $ matches as $ match ) { if ( ! in_array ( $ match [ 1 ] . $ match [ 2 ] , $ data , true ) ) { $ data [ ] = $ match [ 1 ] . $ match [ 2 ] ; try { DB :: table ( 'link' ) -> insert ( [ 'l_from' => $ xref , 'l_to' => $ match [ 2 ] , 'l_type' => $ match [ 1 ] , 'l_file' => $ ged_id , ] ) ; } catch ( PDOException $ ex ) { } } } } }
|
Extract all the links from the given record and insert them into the database
|
7,427
|
public static function updateNames ( $ xref , $ ged_id , GedcomRecord $ record ) : void { foreach ( $ record -> getAllNames ( ) as $ n => $ name ) { if ( $ record instanceof Individual ) { if ( $ name [ 'givn' ] === '@P.N.' ) { $ soundex_givn_std = null ; $ soundex_givn_dm = null ; } else { $ soundex_givn_std = Soundex :: russell ( $ name [ 'givn' ] ) ; $ soundex_givn_dm = Soundex :: daitchMokotoff ( $ name [ 'givn' ] ) ; } if ( $ name [ 'surn' ] === '@N.N.' ) { $ soundex_surn_std = null ; $ soundex_surn_dm = null ; } else { $ soundex_surn_std = Soundex :: russell ( $ name [ 'surname' ] ) ; $ soundex_surn_dm = Soundex :: daitchMokotoff ( $ name [ 'surname' ] ) ; } DB :: table ( 'name' ) -> insert ( [ 'n_file' => $ ged_id , 'n_id' => $ xref , 'n_num' => $ n , 'n_type' => $ name [ 'type' ] , 'n_sort' => mb_substr ( $ name [ 'sort' ] , 0 , 255 ) , 'n_full' => mb_substr ( $ name [ 'fullNN' ] , 0 , 255 ) , 'n_surname' => mb_substr ( $ name [ 'surname' ] , 0 , 255 ) , 'n_surn' => mb_substr ( $ name [ 'surn' ] , 0 , 255 ) , 'n_givn' => mb_substr ( $ name [ 'givn' ] , 0 , 255 ) , 'n_soundex_givn_std' => $ soundex_givn_std , 'n_soundex_surn_std' => $ soundex_surn_std , 'n_soundex_givn_dm' => $ soundex_givn_dm , 'n_soundex_surn_dm' => $ soundex_surn_dm , ] ) ; } else { DB :: table ( 'name' ) -> insert ( [ 'n_file' => $ ged_id , 'n_id' => $ xref , 'n_num' => $ n , 'n_type' => $ name [ 'type' ] , 'n_sort' => mb_substr ( $ name [ 'sort' ] , 0 , 255 ) , 'n_full' => mb_substr ( $ name [ 'fullNN' ] , 0 , 255 ) , ] ) ; } } }
|
Extract all the names from the given record and insert them into the database .
|
7,428
|
public static function convertInlineMedia ( Tree $ tree , $ gedrec ) : string { while ( preg_match ( '/\n1 OBJE(?:\n[2-9].+)+/' , $ gedrec , $ match ) ) { $ gedrec = str_replace ( $ match [ 0 ] , self :: createMediaObject ( 1 , $ match [ 0 ] , $ tree ) , $ gedrec ) ; } while ( preg_match ( '/\n2 OBJE(?:\n[3-9].+)+/' , $ gedrec , $ match ) ) { $ gedrec = str_replace ( $ match [ 0 ] , self :: createMediaObject ( 2 , $ match [ 0 ] , $ tree ) , $ gedrec ) ; } while ( preg_match ( '/\n3 OBJE(?:\n[4-9].+)+/' , $ gedrec , $ match ) ) { $ gedrec = str_replace ( $ match [ 0 ] , self :: createMediaObject ( 3 , $ match [ 0 ] , $ tree ) , $ gedrec ) ; } return $ gedrec ; }
|
Extract inline media data and convert to media objects .
|
7,429
|
public static function createMediaObject ( $ level , $ gedrec , Tree $ tree ) : string { if ( preg_match ( '/\n\d FILE (.+)/' , $ gedrec , $ file_match ) ) { $ file = $ file_match [ 1 ] ; } else { $ file = '' ; } if ( preg_match ( '/\n\d TITL (.+)/' , $ gedrec , $ file_match ) ) { $ titl = $ file_match [ 1 ] ; } else { $ titl = '' ; } $ xref = DB :: table ( 'media_file' ) -> where ( 'm_file' , '=' , $ tree -> id ( ) ) -> where ( 'descriptive_title' , '=' , $ titl ) -> where ( 'multimedia_file_refn' , '=' , mb_substr ( $ file , 0 , 248 ) ) -> value ( 'm_id' ) ; if ( ! $ xref ) { $ xref = $ tree -> getNewXref ( ) ; $ gedrec = preg_replace_callback ( '/\n(\d+)/' , static function ( array $ m ) use ( $ level ) : string { return "\n" . ( $ m [ 1 ] - $ level ) ; } , $ gedrec ) ; $ gedrec = str_replace ( "\n0 OBJE\n" , '0 @' . $ xref . "@ OBJE\n" , $ gedrec ) ; $ gedrec = preg_replace ( '/\n1 FORM (.+)\n1 FILE (.+)\n1 TITL (.+)/' , "\n1 FILE $2\n2 FORM $1\n2 TITL $3" , $ gedrec ) ; $ gedrec = preg_replace ( '/\n1 FORM (.+)\n1 TITL (.+)\n1 FILE (.+)/' , "\n1 FILE $3\n2 FORM $1\n2 TITL $2" , $ gedrec ) ; $ gedrec = preg_replace ( '/\n1 FILE (.+)\n1 FORM (.+)\n1 TITL (.+)/' , "\n1 FILE $1\n2 FORM $2\n2 TITL $3" , $ gedrec ) ; $ record = new Media ( $ xref , $ gedrec , null , $ tree ) ; DB :: table ( 'media' ) -> insert ( [ 'm_id' => $ xref , 'm_file' => $ tree -> id ( ) , 'm_gedcom' => $ gedrec , ] ) ; foreach ( $ record -> mediaFiles ( ) as $ media_file ) { DB :: table ( 'media_file' ) -> insert ( [ 'm_id' => $ xref , 'm_file' => $ tree -> id ( ) , 'multimedia_file_refn' => mb_substr ( $ media_file -> filename ( ) , 0 , 248 ) , 'multimedia_format' => mb_substr ( $ media_file -> format ( ) , 0 , 4 ) , 'source_media_type' => mb_substr ( $ media_file -> type ( ) , 0 , 15 ) , 'descriptive_title' => mb_substr ( $ media_file -> title ( ) , 0 , 248 ) , ] ) ; } } return "\n" . $ level . ' OBJE @' . $ xref . '@' ; }
|
Create a new media object from inline media data .
|
7,430
|
public static function acceptAllChanges ( $ xref , Tree $ tree ) : void { $ changes = DB :: table ( 'change' ) -> join ( 'gedcom' , 'change.gedcom_id' , '=' , 'gedcom.gedcom_id' ) -> where ( 'status' , '=' , 'pending' ) -> where ( 'xref' , '=' , $ xref ) -> where ( 'gedcom.gedcom_id' , '=' , $ tree -> id ( ) ) -> orderBy ( 'change_id' ) -> select ( [ 'change_id' , 'gedcom_name' , 'old_gedcom' , 'new_gedcom' ] ) -> get ( ) ; foreach ( $ changes as $ change ) { if ( empty ( $ change -> new_gedcom ) ) { self :: updateRecord ( $ change -> old_gedcom , $ tree , true ) ; } else { self :: updateRecord ( $ change -> new_gedcom , $ tree , false ) ; } DB :: table ( 'change' ) -> where ( 'change_id' , '=' , $ change -> change_id ) -> update ( [ 'status' => 'accepted' ] ) ; Log :: addEditLog ( "Accepted change {$change->change_id} for {$xref} / {$change->gedcom_name} into database" , $ tree ) ; } }
|
Accept all pending changes for a specified record .
|
7,431
|
public function show ( ServerRequestInterface $ request , Tree $ tree , ClipboardService $ clipboard_service ) : ResponseInterface { $ xref = $ request -> get ( 'xref' , '' ) ; $ record = Note :: getInstance ( $ xref , $ tree ) ; Auth :: checkNoteAccess ( $ record , false ) ; return $ this -> viewResponse ( 'note-page' , [ 'clipboard_facts' => $ clipboard_service -> pastableFacts ( $ record , new Collection ( ) ) , 'facts' => $ this -> facts ( $ record ) , 'families' => $ record -> linkedFamilies ( 'NOTE' ) , 'individuals' => $ record -> linkedIndividuals ( 'NOTE' ) , 'note' => $ record , 'notes' => [ ] , 'media_objects' => $ record -> linkedMedia ( 'NOTE' ) , 'meta_robots' => 'index,follow' , 'sources' => $ record -> linkedSources ( 'NOTE' ) , 'text' => Filter :: formatText ( $ record -> getNote ( ) , $ tree ) , 'title' => $ record -> fullName ( ) , ] ) ; }
|
Show a note s page .
|
7,432
|
public function analyticsSnippet ( array $ parameters ) : string { $ tree = app ( Tree :: class ) ; $ user = app ( UserInterface :: class ) ; $ parameters [ 'dimensions' ] = ( object ) [ 'dimension1' => $ tree instanceof Tree ? $ tree -> name ( ) : '-' , 'dimension2' => $ tree instanceof Tree ? Auth :: accessLevel ( $ tree , $ user ) : '-' , ] ; return view ( 'modules/google-analytics/snippet' , $ parameters ) ; }
|
Embed placeholders in the snippet .
|
7,433
|
public static function statusName ( string $ status_code ) : string { switch ( $ status_code ) { case 'BIC' : return I18N :: translate ( 'Born in the covenant' ) ; case 'CANCELED' : return I18N :: translate ( 'Sealing canceled (divorce)' ) ; case 'CHILD' : return I18N :: translate ( 'Died as a child: exempt' ) ; case 'CLEARED' : return I18N :: translate ( 'Cleared but not yet completed' ) ; case 'COMPLETED' : return I18N :: translate ( 'Completed; date unknown' ) ; case 'DNS' : return I18N :: translate ( 'Do not seal: unauthorized' ) ; case 'DNS/CAN' : return I18N :: translate ( 'Do not seal, previous sealing canceled' ) ; case 'EXCLUDED' : return I18N :: translate ( 'Excluded from this submission' ) ; case 'INFANT' : return I18N :: translate ( 'Died as an infant: exempt' ) ; case 'PRE-1970' : return I18N :: translate ( 'Completed before 1970; date not available' ) ; case 'STILLBORN' : return I18N :: translate ( 'Stillborn: exempt' ) ; case 'SUBMITTED' : return I18N :: translate ( 'Submitted but not yet cleared' ) ; case 'UNCLEARED' : return I18N :: translate ( 'Uncleared: insufficient data' ) ; default : return $ status_code ; } }
|
Get the localized name for a status code
|
7,434
|
public static function statusNames ( string $ tag ) : array { $ status_names = [ ] ; foreach ( self :: statusCodes ( $ tag ) as $ status_code ) { $ status_names [ $ status_code ] = self :: statusName ( $ status_code ) ; } uasort ( $ status_names , '\Fisharebest\Webtrees\I18N::strcasecmp' ) ; return $ status_names ; }
|
A sorted list of all status names for a given GEDCOM tag
|
7,435
|
protected function addNewFact ( ServerRequestInterface $ request , Tree $ tree , $ fact ) : string { $ FACT = $ request -> get ( $ fact , '' ) ; $ DATE = $ request -> get ( $ fact . '_DATE' , '' ) ; $ PLAC = $ request -> get ( $ fact . '_PLAC' , '' ) ; if ( $ DATE !== '' || $ PLAC !== '' || $ FACT !== '' && $ FACT !== 'Y' ) { if ( $ FACT !== '' && $ FACT !== 'Y' ) { $ gedrec = "\n1 " . $ fact . ' ' . $ FACT ; } else { $ gedrec = "\n1 " . $ fact ; } if ( $ DATE ) { $ gedrec .= "\n2 DATE " . $ DATE ; } if ( $ PLAC ) { $ gedrec .= "\n2 PLAC " . $ PLAC ; if ( preg_match_all ( '/(' . Gedcom :: REGEX_TAG . ')/' , $ tree -> getPreference ( 'ADVANCED_PLAC_FACTS' ) , $ match ) ) { foreach ( $ match [ 1 ] as $ tag ) { $ TAG = $ request -> get ( $ fact . '_' . $ tag , '' ) ; if ( $ TAG !== '' ) { $ gedrec .= "\n3 " . $ tag . ' ' . $ TAG ; } } } $ LATI = $ request -> get ( $ fact . '_LATI' , '' ) ; $ LONG = $ request -> get ( $ fact . '_LONG' , '' ) ; if ( $ LATI !== '' || $ LONG !== '' ) { $ gedrec .= "\n3 MAP\n4 LATI " . $ LATI . "\n4 LONG " . $ LONG ; } } if ( ( bool ) $ request -> get ( 'SOUR_' . $ fact ) ) { return $ this -> updateSource ( $ gedrec , 2 ) ; } return $ gedrec ; } if ( $ FACT === 'Y' ) { if ( ( bool ) $ request -> get ( 'SOUR_' . $ fact ) ) { return $ this -> updateSource ( "\n1 " . $ fact . ' Y' , 2 ) ; } return "\n1 " . $ fact . ' Y' ; } return '' ; }
|
Create a form to add a new fact .
|
7,436
|
protected function addNewName ( ServerRequestInterface $ request , Tree $ tree ) : string { $ gedrec = "\n1 NAME " . $ request -> get ( 'NAME' , '' ) ; $ tags = [ 'NPFX' , 'GIVN' , 'SPFX' , 'SURN' , 'NSFX' , ] ; if ( preg_match_all ( '/(' . Gedcom :: REGEX_TAG . ')/' , $ tree -> getPreference ( 'ADVANCED_NAME_FACTS' ) , $ match ) ) { $ tags = array_merge ( $ tags , $ match [ 1 ] ) ; } $ SURNAME_TRADITION = $ tree -> getPreference ( 'SURNAME_TRADITION' ) ; if ( $ SURNAME_TRADITION === 'paternal' || $ SURNAME_TRADITION === 'polish' || $ SURNAME_TRADITION === 'lithuanian' ) { $ tags [ ] = '_MARNM' ; } foreach ( array_unique ( $ tags ) as $ tag ) { $ TAG = $ request -> get ( $ tag , '' ) ; if ( $ TAG !== '' ) { $ gedrec .= "\n2 {$tag} {$TAG}" ; } } return $ gedrec ; }
|
Assemble the pieces of a newly created record into gedcom
|
7,437
|
public function handle ( ServerRequestInterface $ request ) : ResponseInterface { $ module_name = $ request -> getQueryParams ( ) [ 'module' ] ?? $ request -> getParsedBody ( ) [ 'module' ] ?? '' ; $ action = $ request -> getQueryParams ( ) [ 'action' ] ?? $ request -> getParsedBody ( ) [ 'action' ] ?? '' ; $ module = $ this -> module_service -> findByName ( $ module_name ) ; if ( $ module === null ) { throw new NotFoundHttpException ( 'Module ' . $ module_name . ' does not exist' ) ; } $ verb = strtolower ( $ request -> getMethod ( ) ) ; $ method = $ verb . $ action . 'Action' ; if ( strpos ( $ action , 'Admin' ) !== false && ! Auth :: isAdmin ( $ this -> user ) ) { throw new AccessDeniedHttpException ( 'Admin only action' ) ; } if ( ! method_exists ( $ module , $ method ) ) { throw new NotFoundHttpException ( 'Method ' . $ method . '() not found in ' . $ module_name ) ; } return app ( ) -> dispatch ( $ module , $ method ) ; }
|
Perform an HTTP action for one of the modules .
|
7,438
|
private function getFactsWithMedia ( Individual $ individual ) : Collection { if ( $ this -> facts === null ) { $ facts = $ individual -> facts ( ) ; foreach ( $ individual -> spouseFamilies ( ) as $ family ) { if ( $ family -> canShow ( ) ) { foreach ( $ family -> facts ( ) as $ fact ) { $ facts -> push ( $ fact ) ; } } } $ this -> facts = new Collection ( ) ; foreach ( $ facts as $ fact ) { if ( preg_match ( '/(?:^1|\n\d) OBJE @' . Gedcom :: REGEX_XREF . '@/' , $ fact -> gedcom ( ) ) ) { $ this -> facts -> push ( $ fact ) ; } } $ this -> facts = Fact :: sortFacts ( $ this -> facts ) ; } return $ this -> facts ; }
|
Get all the facts for an individual which contain media objects .
|
7,439
|
public function father ( Individual $ individual ) : ? Individual { $ family = $ individual -> primaryChildFamily ( ) ; if ( $ family ) { return $ family -> husband ( ) ; } return null ; }
|
Find the father of an individual
|
7,440
|
public function mother ( Individual $ individual ) : ? Individual { $ family = $ individual -> primaryChildFamily ( ) ; if ( $ family ) { return $ family -> wife ( ) ; } return null ; }
|
Find the mother of an individual
|
7,441
|
public function spouseFamily ( Individual $ individual ) : ? Family { $ families = [ ] ; foreach ( $ individual -> spouseFamilies ( ) as $ family ) { if ( Date :: compare ( $ family -> getMarriageDate ( ) , $ this -> date ( ) ) <= 0 ) { $ families [ ] = $ family ; } } if ( empty ( $ families ) ) { return null ; } usort ( $ families , static function ( Family $ x , Family $ y ) : int { return Date :: compare ( $ x -> getMarriageDate ( ) , $ y -> getMarriageDate ( ) ) ; } ) ; return end ( $ families ) ; }
|
Find the current spouse family of an individual
|
7,442
|
protected function notCountry ( string $ place ) : string { $ parts = explode ( ', ' , $ place ) ; if ( end ( $ parts ) === $ this -> place ( ) ) { return implode ( ', ' , array_slice ( $ parts , 0 , - 1 ) ) ; } return $ place ; }
|
Remove the country of a place name where it is the same as the census place
|
7,443
|
public function alphabet ( ) : array { $ locale = $ this -> locale -> languageTag ( ) ; $ script = $ this -> locale -> script ( ) -> code ( ) ; return self :: ALPHABETS_FOR_LOCALE [ $ locale ] ?? self :: ALPHABETS_FOR_SCRIPT [ $ script ] ?? self :: LATIN_ALPHABET ; }
|
Which alphabet is used in a locale?
|
7,444
|
public function calendar ( ) : CalendarInterface { $ non_gregorian_calendars = [ 'ar' => new ArabicCalendar ( ) , 'fa' => new PersianCalendar ( ) , 'he' => new JewishCalendar ( ) , 'yi' => new JewishCalendar ( ) , ] ; return $ non_gregorian_calendars [ $ this -> locale -> languageTag ( ) ] ?? new GregorianCalendar ( ) ; }
|
Which calendar is used in a locale?
|
7,445
|
public function loginPage ( ServerRequestInterface $ request , ? Tree $ tree ) : ResponseInterface { if ( Auth :: check ( ) ) { $ ged = $ tree !== null ? $ tree -> name ( ) : '' ; return redirect ( route ( 'user-page' , [ 'ged' => $ ged ] ) ) ; } $ error = $ request -> get ( 'error' , '' ) ; $ url = $ request -> get ( 'url' , '' ) ; $ username = $ request -> get ( 'username' , '' ) ; $ title = I18N :: translate ( 'Sign in' ) ; switch ( Site :: getPreference ( 'WELCOME_TEXT_AUTH_MODE' ) ) { case 1 : default : $ welcome = I18N :: translate ( 'Anyone with a user account can access this website.' ) ; break ; case 2 : $ welcome = I18N :: translate ( 'You need to be an authorized user to access this website.' ) ; break ; case 3 : $ welcome = I18N :: translate ( 'You need to be a family member to access this website.' ) ; break ; case 4 : $ welcome = Site :: getPreference ( 'WELCOME_TEXT_AUTH_MODE_' . WT_LOCALE ) ; break ; } if ( Site :: getPreference ( 'USE_REGISTRATION_MODULE' ) === '1' ) { $ welcome .= ' ' . I18N :: translate ( 'You can apply for an account using the link below.' ) ; } $ can_register = Site :: getPreference ( 'USE_REGISTRATION_MODULE' ) === '1' ; return $ this -> viewResponse ( 'login-page' , [ 'can_register' => $ can_register , 'error' => $ error , 'title' => $ title , 'url' => $ url , 'username' => $ username , 'welcome' => $ welcome , ] ) ; }
|
Show a login page .
|
7,446
|
public function loginAction ( ServerRequestInterface $ request , UpgradeService $ upgrade_service ) : ResponseInterface { $ username = $ request -> get ( 'username' , '' ) ; $ password = $ request -> get ( 'password' , '' ) ; $ url = $ request -> get ( 'url' , '' ) ; try { $ this -> doLogin ( $ username , $ password ) ; if ( Auth :: isAdmin ( ) && $ upgrade_service -> isUpgradeAvailable ( ) ) { FlashMessages :: addMessage ( I18N :: translate ( 'A new version of webtrees is available.' ) . ' <a class="alert-link" href="' . e ( route ( 'upgrade' ) ) . '">' . I18N :: translate ( 'Upgrade to webtrees %s.' , '<span dir="ltr">' . $ upgrade_service -> latestVersion ( ) . '</span>' ) . '</a>' ) ; } if ( $ url === '' ) { $ ged = ( string ) DB :: table ( 'gedcom' ) -> join ( 'user_gedcom_setting' , 'gedcom.gedcom_id' , '=' , 'user_gedcom_setting.gedcom_id' ) -> where ( 'user_id' , '=' , Auth :: id ( ) ) -> value ( 'gedcom_name' ) ; $ url = route ( 'tree-page' , [ 'ged' => $ ged ] ) ; } return redirect ( $ url ) ; } catch ( Exception $ ex ) { return redirect ( route ( 'login' , [ 'username' => $ username , 'url' => $ url , 'error' => $ ex -> getMessage ( ) , ] ) ) ; } }
|
Perform a login .
|
7,447
|
private function doLogin ( string $ username , string $ password ) : void { if ( ! $ _COOKIE ) { Log :: addAuthenticationLog ( 'Login failed (no session cookies): ' . $ username ) ; throw new Exception ( I18N :: translate ( 'You cannot sign in because your browser does not accept cookies.' ) ) ; } $ user = $ this -> user_service -> findByIdentifier ( $ username ) ; if ( $ user === null ) { Log :: addAuthenticationLog ( 'Login failed (no such user/email): ' . $ username ) ; throw new Exception ( I18N :: translate ( 'The username or password is incorrect.' ) ) ; } if ( ! $ user -> checkPassword ( $ password ) ) { Log :: addAuthenticationLog ( 'Login failed (incorrect password): ' . $ username ) ; throw new Exception ( I18N :: translate ( 'The username or password is incorrect.' ) ) ; } if ( ! $ user -> getPreference ( 'verified' ) ) { Log :: addAuthenticationLog ( 'Login failed (not verified by user): ' . $ username ) ; throw new Exception ( I18N :: translate ( 'This account has not been verified. Please check your email for a verification message.' ) ) ; } if ( ! $ user -> getPreference ( 'verified_by_admin' ) ) { Log :: addAuthenticationLog ( 'Login failed (not approved by admin): ' . $ username ) ; throw new Exception ( I18N :: translate ( 'This account has not been approved. Please wait for an administrator to approve it.' ) ) ; } Auth :: login ( $ user ) ; Log :: addAuthenticationLog ( 'Login: ' . Auth :: user ( ) -> userName ( ) . '/' . Auth :: user ( ) -> realName ( ) ) ; Auth :: user ( ) -> setPreference ( 'sessiontime' , ( string ) Carbon :: now ( ) -> unix ( ) ) ; Session :: put ( 'language' , Auth :: user ( ) -> getPreference ( 'language' ) ) ; Session :: put ( 'theme' , Auth :: user ( ) -> getPreference ( 'theme' ) ) ; I18N :: init ( Auth :: user ( ) -> getPreference ( 'language' ) ) ; }
|
Log in if we can . Throw an exception if we can t .
|
7,448
|
public function logoutAction ( Tree $ tree = null ) : ResponseInterface { if ( Auth :: check ( ) ) { Log :: addAuthenticationLog ( 'Logout: ' . Auth :: user ( ) -> userName ( ) . '/' . Auth :: user ( ) -> realName ( ) ) ; Auth :: logout ( ) ; FlashMessages :: addMessage ( I18N :: translate ( 'You have signed out.' ) , 'info' ) ; } if ( $ tree === null ) { return redirect ( route ( 'tree-page' ) ) ; } return redirect ( route ( 'tree-page' , [ 'ged' => $ tree -> name ( ) ] ) ) ; }
|
Perform a logout .
|
7,449
|
public function sosaStradonitzAncestors ( Individual $ individual , int $ generations ) : Collection { $ ancestors = [ 1 => $ individual ] ; $ queue = [ 1 ] ; $ max = 2 ** ( $ generations - 1 ) ; while ( ! empty ( $ queue ) ) { $ sosa_stradonitz_number = array_shift ( $ queue ) ; if ( $ sosa_stradonitz_number >= $ max ) { break ; } $ family = $ ancestors [ $ sosa_stradonitz_number ] -> primaryChildFamily ( ) ; if ( $ family instanceof Family ) { if ( $ family -> husband ( ) instanceof Individual ) { $ ancestors [ $ sosa_stradonitz_number * 2 ] = $ family -> husband ( ) ; $ queue [ ] = $ sosa_stradonitz_number * 2 ; } if ( $ family -> wife ( ) instanceof Individual ) { $ ancestors [ $ sosa_stradonitz_number * 2 + 1 ] = $ family -> wife ( ) ; $ queue [ ] = $ sosa_stradonitz_number * 2 + 1 ; } } } return new Collection ( $ ancestors ) ; }
|
Find the ancestors of an individual indexed by their Sosa - Stradonitz number .
|
7,450
|
public function descendants ( Individual $ individual , int $ generations ) : Collection { $ descendants = new Collection ( [ $ individual ] ) ; if ( $ generations > 0 ) { foreach ( $ individual -> spouseFamilies ( ) as $ family ) { foreach ( $ family -> children ( ) as $ child ) { $ descendants = $ descendants -> merge ( $ this -> descendants ( $ child , $ generations - 1 ) ) ; } } } return $ descendants ; }
|
Find the descendants of an individual .
|
7,451
|
public function centuryName ( int $ century ) : string { if ( $ century < 0 ) { return I18N :: translate ( '%s BCE' , $ this -> centuryName ( - $ century ) ) ; } switch ( $ century ) { case 21 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '21st' ) ) ; case 20 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '20th' ) ) ; case 19 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '19th' ) ) ; case 18 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '18th' ) ) ; case 17 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '17th' ) ) ; case 16 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '16th' ) ) ; case 15 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '15th' ) ) ; case 14 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '14th' ) ) ; case 13 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '13th' ) ) ; case 12 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '12th' ) ) ; case 11 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '11th' ) ) ; case 10 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '10th' ) ) ; case 9 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '9th' ) ) ; case 8 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '8th' ) ) ; case 7 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '7th' ) ) ; case 6 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '6th' ) ) ; case 5 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '5th' ) ) ; case 4 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '4th' ) ) ; case 3 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '3rd' ) ) ; case 2 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '2nd' ) ) ; case 1 : return strip_tags ( I18N :: translateContext ( 'CENTURY' , '1st' ) ) ; default : return ( $ century - 1 ) . '01-' . $ century . '00' ; } }
|
Century name English = > 21st Polish = > XXI etc .
|
7,452
|
public static function enable ( ) : void { self :: $ debugbar = new StandardDebugBar ( ) ; self :: $ debugbar -> addCollector ( new ViewCollector ( ) ) ; self :: $ renderer = self :: $ debugbar -> getJavascriptRenderer ( './vendor/maximebf/debugbar/src/DebugBar/Resources/' ) ; }
|
Initialize the Debugbar .
|
7,453
|
public static function initPDO ( PDO $ pdo ) : PDO { if ( self :: $ debugbar instanceof StandardDebugBar ) { $ traceable_pdo = new TraceablePDO ( $ pdo ) ; self :: $ debugbar -> addCollector ( new PDOCollector ( $ traceable_pdo ) ) ; } return $ pdo ; }
|
Initialize the PDO collector .
|
7,454
|
public static function stopMeasure ( $ name ) : void { if ( self :: $ debugbar instanceof StandardDebugBar ) { $ collector = self :: $ debugbar -> getCollector ( 'time' ) ; if ( $ collector instanceof TimeDataCollector ) { $ collector -> stopMeasure ( $ name ) ; } } }
|
Stop a timer .
|
7,455
|
public function addView ( string $ view , array $ data ) : void { $ num = count ( $ this -> views ) + 1 ; $ key = '#' . $ num . ' ' . $ view ; $ this -> views [ $ key ] = $ this -> getDataFormatter ( ) -> formatVar ( $ data ) ; }
|
Add details about a view
|
7,456
|
public function editMediaFile ( ServerRequestInterface $ request , Tree $ tree ) : ResponseInterface { $ xref = $ request -> get ( 'xref' , '' ) ; $ fact_id = $ request -> get ( 'fact_id' , '' ) ; $ media = Media :: getInstance ( $ xref , $ tree ) ; try { Auth :: checkMediaAccess ( $ media ) ; } catch ( Exception $ ex ) { return response ( view ( 'modals/error' , [ 'title' => I18N :: translate ( 'Edit a media file' ) , 'error' => $ ex -> getMessage ( ) , ] ) , StatusCodeInterface :: STATUS_FORBIDDEN ) ; } foreach ( $ media -> mediaFiles ( ) as $ media_file ) { if ( $ media_file -> factId ( ) === $ fact_id ) { return response ( view ( 'modals/edit-media-file' , [ 'media_file' => $ media_file , 'max_upload_size' => $ this -> maxUploadFilesize ( ) , 'media' => $ media , 'media_types' => $ this -> mediaTypes ( ) , 'unused_files' => $ this -> unusedFiles ( $ tree ) , ] ) ) ; } } return response ( '' , StatusCodeInterface :: STATUS_NOT_FOUND ) ; }
|
Edit an existing media file .
|
7,457
|
public function createMediaObject ( Tree $ tree ) : ResponseInterface { return response ( view ( 'modals/create-media-object' , [ 'max_upload_size' => $ this -> maxUploadFilesize ( ) , 'media_types' => $ this -> mediaTypes ( ) , 'unused_files' => $ this -> unusedFiles ( $ tree ) , ] ) ) ; }
|
Show a form to create a new media object .
|
7,458
|
public function createMediaObjectAction ( ServerRequestInterface $ request , Tree $ tree ) : ResponseInterface { $ note = $ request -> get ( 'note' ) ; $ title = $ request -> get ( 'title' ) ; $ type = $ request -> get ( 'type' ) ; $ privacy_restriction = $ request -> get ( 'privacy-restriction' , '' ) ; $ edit_restriction = $ request -> get ( 'edit-restriction' , '' ) ; $ type = trim ( preg_replace ( '/\s+/' , ' ' , $ type ) ) ; $ title = trim ( preg_replace ( '/\s+/' , ' ' , $ title ) ) ; $ note = str_replace ( [ "\r\n" , "\r" , "\n" , ] , "\n1 CONT " , $ note ) ; $ file = $ this -> uploadFile ( $ request , $ tree ) ; if ( $ file === '' ) { return response ( [ 'error_message' => I18N :: translate ( 'There was an error uploading your file.' ) ] , 406 ) ; } $ gedcom = "0 @@ OBJE\n" . $ this -> createMediaFileGedcom ( $ file , $ type , $ title ) ; if ( $ note !== '' ) { $ gedcom .= "\n1 NOTE " . preg_replace ( '/\r?\n/' , "\n2 CONT " , $ note ) ; } if ( in_array ( $ privacy_restriction , self :: PRIVACY_RESTRICTIONS , true ) ) { $ gedcom .= "\n1 RESN " . $ privacy_restriction ; } if ( in_array ( $ edit_restriction , self :: EDIT_RESTRICTIONS , true ) ) { $ gedcom .= "\n1 RESN " . $ edit_restriction ; } $ record = $ tree -> createMediaObject ( $ gedcom ) ; FunctionsImport :: acceptAllChanges ( $ record -> xref ( ) , $ record -> tree ( ) ) ; return response ( [ 'id' => $ record -> xref ( ) , 'text' => view ( 'selects/media' , [ 'media' => $ record , ] ) , 'html' => view ( 'modals/record-created' , [ 'title' => I18N :: translate ( 'The media object has been created' ) , 'name' => $ record -> fullName ( ) , 'url' => $ record -> url ( ) , ] ) , ] ) ; }
|
Process a form to create a new media object .
|
7,459
|
private function createMediaFileGedcom ( string $ file , string $ type , string $ title ) : string { if ( preg_match ( '/\.([a-z0-9]+)/i' , $ file , $ match ) ) { $ extension = strtolower ( $ match [ 1 ] ) ; $ extension = str_replace ( 'jpg' , 'jpeg' , $ extension ) ; $ extension = ' ' . $ extension ; } else { $ extension = '' ; } $ gedcom = '1 FILE ' . $ file ; if ( $ type !== '' ) { $ gedcom .= "\n2 FORM" . $ extension . "\n3 TYPE " . $ type ; } if ( $ title !== '' ) { $ gedcom .= "\n2 TITL " . $ title ; } return $ gedcom ; }
|
Convert the media file attributes into GEDCOM format .
|
7,460
|
private function maxUploadFilesize ( ) : string { $ bytes = UploadedFile :: getMaxFilesize ( ) ; $ kb = intdiv ( $ bytes + 1023 , 1024 ) ; return I18N :: translate ( '%s KB' , I18N :: number ( $ kb ) ) ; }
|
What is the largest file a user may upload?
|
7,461
|
private function unusedFiles ( Tree $ tree ) : array { $ used_files = DB :: table ( 'media_file' ) -> where ( 'm_file' , '=' , $ tree -> id ( ) ) -> where ( 'multimedia_file_refn' , 'NOT LIKE' , 'http://%' ) -> where ( 'multimedia_file_refn' , 'NOT LIKE' , 'https://%' ) -> pluck ( 'multimedia_file_refn' ) -> all ( ) ; $ disk_files = [ ] ; $ media_dir = WT_DATA_DIR . $ tree -> getPreference ( 'MEDIA_DIRECTORY' , 'media/' ) ; $ iter = new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ media_dir , FilesystemIterator :: FOLLOW_SYMLINKS ) ) ; foreach ( $ iter as $ file ) { if ( $ file -> isFile ( ) ) { $ filename = substr ( $ file -> getPathname ( ) , strlen ( $ media_dir ) ) ; if ( strpos ( $ filename , 'thumbs/' ) !== 0 && strpos ( $ filename , 'watermarks/' ) !== 0 ) { $ disk_files [ ] = $ filename ; } } } $ unused_files = array_diff ( $ disk_files , $ used_files ) ; sort ( $ unused_files ) ; return array_combine ( $ unused_files , $ unused_files ) ; }
|
A list of media files not already linked to a media object .
|
7,462
|
public function setup ( ) : void { parent :: setup ( ) ; $ this -> pdf = new ReportTcpdf ( $ this -> orientation , parent :: UNITS , [ $ this -> page_width , $ this -> page_height , ] , self :: UNICODE , 'UTF-8' , self :: DISK_CACHE ) ; $ this -> pdf -> SetMargins ( $ this -> left_margin , $ this -> top_margin , $ this -> right_margin ) ; $ this -> pdf -> setHeaderMargin ( $ this -> header_margin ) ; $ this -> pdf -> setFooterMargin ( $ this -> footer_margin ) ; $ this -> pdf -> SetAutoPageBreak ( true , $ this -> bottom_margin ) ; $ this -> pdf -> setFontSubsetting ( self :: SUBSETTING ) ; $ this -> pdf -> SetCompression ( self :: COMPRESSION ) ; $ this -> pdf -> setRTL ( $ this -> rtl ) ; $ this -> pdf -> SetCreator ( Webtrees :: NAME . ' ' . Webtrees :: VERSION ) ; $ this -> pdf -> SetAuthor ( $ this -> rauthor ) ; $ this -> pdf -> SetTitle ( $ this -> title ) ; $ this -> pdf -> SetSubject ( $ this -> rsubject ) ; $ this -> pdf -> SetKeywords ( $ this -> rkeywords ) ; $ this -> pdf -> setReport ( $ this ) ; if ( $ this -> show_generated_by ) { $ element = new ReportPdfCell ( 0 , 10 , 0 , 'C' , '' , 'genby' , 1 , ReportBaseElement :: CURRENT_POSITION , ReportBaseElement :: CURRENT_POSITION , 0 , 0 , '' , '' , true ) ; $ element -> addText ( $ this -> generated_by ) ; $ element -> setUrl ( Webtrees :: NAME . ' ' . Webtrees :: VERSION ) ; $ this -> pdf -> addFooter ( $ element ) ; } }
|
PDF Setup - ReportPdf
|
7,463
|
public function createImage ( string $ file , float $ x , float $ y , float $ w , float $ h , string $ align , string $ ln ) : ReportBaseImage { return new ReportPdfImage ( $ file , $ x , $ y , $ w , $ h , $ align , $ ln ) ; }
|
Create a new image object .
|
7,464
|
public static function url ( $ path , array $ data ) : string { $ path = str_replace ( ' ' , '%20' , $ path ) ; return $ path . '?' . http_build_query ( $ data , '' , '&' , PHP_QUERY_RFC3986 ) ; }
|
Encode a URL .
|
7,465
|
protected function findScopeSelectors ( $ scope , $ depth ) { if ( $ scope -> depth === $ depth && $ scope -> selectors ) { return $ scope -> selectors ; } if ( $ scope -> children ) { foreach ( array_reverse ( $ scope -> children ) as $ c ) { if ( $ s = $ this -> findScopeSelectors ( $ c , $ depth ) ) { return $ s ; } } } return [ ] ; }
|
Find a selector by the depth node in the scope
|
7,466
|
protected function compileChildren ( $ stms , OutputBlock $ out ) { foreach ( $ stms as $ stm ) { $ ret = $ this -> compileChild ( $ stm , $ out ) ; if ( isset ( $ ret ) ) { return $ ret ; } } return null ; }
|
Compile children and return result
|
7,467
|
protected function joinSelectors ( $ parent , $ child , $ selfParentSelectors = null ) { $ setSelf = false ; $ out = [ ] ; foreach ( $ child as $ part ) { $ newPart = [ ] ; foreach ( $ part as $ p ) { if ( $ p === static :: $ selfSelector ) { $ setSelf = true ; if ( is_null ( $ selfParentSelectors ) ) { $ selfParentSelectors = $ parent ; } foreach ( $ selfParentSelectors as $ i => $ parentPart ) { if ( $ i > 0 ) { $ out [ ] = $ newPart ; $ newPart = [ ] ; } foreach ( $ parentPart as $ pp ) { if ( is_array ( $ pp ) ) { $ flatten = [ ] ; array_walk_recursive ( $ pp , function ( $ a ) use ( & $ flatten ) { $ flatten [ ] = $ a ; } ) ; $ pp = implode ( $ flatten ) ; } $ newPart [ ] = $ pp ; } } } else { $ newPart [ ] = $ p ; } } $ out [ ] = $ newPart ; } return $ setSelf ? $ out : array_merge ( $ parent , $ child ) ; }
|
Join selectors ; looks for & to replace or append parent before child
|
7,468
|
protected function extractEnv ( $ envs ) { for ( $ env = null ; $ e = array_pop ( $ envs ) ; ) { $ e -> parent = $ env ; $ env = $ e ; } return $ env ; }
|
Convert env stack to singly linked list
|
7,469
|
protected function setExisting ( $ name , $ value , Environment $ env , $ valueUnreduced = null ) { $ storeEnv = $ env ; $ hasNamespace = $ name [ 0 ] === '^' || $ name [ 0 ] === '@' || $ name [ 0 ] === '%' ; for ( ; ; ) { if ( array_key_exists ( $ name , $ env -> store ) ) { break ; } if ( ! $ hasNamespace && isset ( $ env -> marker ) ) { $ env = $ storeEnv ; break ; } if ( ! isset ( $ env -> parent ) ) { $ env = $ storeEnv ; break ; } $ env = $ env -> parent ; } $ env -> store [ $ name ] = $ value ; if ( $ valueUnreduced ) { $ env -> storeUnreduced [ $ name ] = $ valueUnreduced ; } }
|
Set existing variable
|
7,470
|
protected function setRaw ( $ name , $ value , Environment $ env , $ valueUnreduced = null ) { $ env -> store [ $ name ] = $ value ; if ( $ valueUnreduced ) { $ env -> storeUnreduced [ $ name ] = $ valueUnreduced ; } }
|
Set raw variable
|
7,471
|
protected function sortArgs ( $ prototype , $ args ) { $ keyArgs = [ ] ; $ posArgs = [ ] ; foreach ( $ args as $ arg ) { list ( $ key , $ value ) = $ arg ; $ key = $ key [ 1 ] ; if ( empty ( $ key ) ) { $ posArgs [ ] = empty ( $ arg [ 2 ] ) ? $ value : $ arg ; } else { $ keyArgs [ $ key ] = $ value ; } } if ( ! isset ( $ prototype ) ) { return [ $ posArgs , $ keyArgs ] ; } $ finalArgs = array_pad ( $ posArgs , count ( $ prototype ) , null ) ; foreach ( $ prototype as $ i => $ names ) { foreach ( ( array ) $ names as $ name ) { if ( isset ( $ keyArgs [ $ name ] ) ) { $ finalArgs [ $ i ] = $ keyArgs [ $ name ] ; } } } return [ $ finalArgs , $ keyArgs ] ; }
|
Sorts keyword arguments
|
7,472
|
protected function coerceValue ( $ value ) { if ( is_array ( $ value ) || $ value instanceof \ ArrayAccess ) { return $ value ; } if ( is_bool ( $ value ) ) { return $ this -> toBool ( $ value ) ; } if ( $ value === null ) { return static :: $ null ; } if ( is_numeric ( $ value ) ) { return new Node \ Number ( $ value , '' ) ; } if ( $ value === '' ) { return static :: $ emptyString ; } if ( preg_match ( '/^(#([0-9a-f]{6})|#([0-9a-f]{3}))$/i' , $ value , $ m ) ) { $ color = [ Type :: T_COLOR ] ; if ( isset ( $ m [ 3 ] ) ) { $ num = hexdec ( $ m [ 3 ] ) ; foreach ( [ 3 , 2 , 1 ] as $ i ) { $ t = $ num & 0xf ; $ color [ $ i ] = $ t << 4 | $ t ; $ num >>= 4 ; } } else { $ num = hexdec ( $ m [ 2 ] ) ; foreach ( [ 3 , 2 , 1 ] as $ i ) { $ color [ $ i ] = $ num & 0xff ; $ num >>= 8 ; } } return $ color ; } return [ Type :: T_KEYWORD , $ value ] ; }
|
Coerce a php value into a scss one
|
7,473
|
public function assertMap ( $ value ) { $ value = $ this -> coerceMap ( $ value ) ; if ( $ value [ 0 ] !== Type :: T_MAP ) { $ this -> throwError ( 'expecting map, %s received' , $ value [ 0 ] ) ; } return $ value ; }
|
Assert value is a map
|
7,474
|
public function assertColor ( $ value ) { if ( $ color = $ this -> coerceColor ( $ value ) ) { return $ color ; } $ this -> throwError ( 'expecting color, %s received' , $ value [ 0 ] ) ; }
|
Assert value is a color
|
7,475
|
protected function hueToRGB ( $ m1 , $ m2 , $ h ) { if ( $ h < 0 ) { $ h += 1 ; } elseif ( $ h > 1 ) { $ h -= 1 ; } if ( $ h * 6 < 1 ) { return $ m1 + ( $ m2 - $ m1 ) * $ h * 6 ; } if ( $ h * 2 < 1 ) { return $ m2 ; } if ( $ h * 3 < 2 ) { return $ m1 + ( $ m2 - $ m1 ) * ( 2 / 3 - $ h ) * 6 ; } return $ m1 ; }
|
Hue to RGB helper
|
7,476
|
protected function inputName ( ) { switch ( true ) { case isset ( $ _GET [ 'p' ] ) : return $ _GET [ 'p' ] ; case isset ( $ _SERVER [ 'PATH_INFO' ] ) : return $ _SERVER [ 'PATH_INFO' ] ; case isset ( $ _SERVER [ 'DOCUMENT_URI' ] ) : return substr ( $ _SERVER [ 'DOCUMENT_URI' ] , strlen ( $ _SERVER [ 'SCRIPT_NAME' ] ) ) ; } }
|
Get name of requested . scss file
|
7,477
|
protected function findInput ( ) { if ( ( $ input = $ this -> inputName ( ) ) && strpos ( $ input , '..' ) === false && substr ( $ input , - 5 ) === '.scss' ) { $ name = $ this -> join ( $ this -> dir , $ input ) ; if ( is_file ( $ name ) && is_readable ( $ name ) ) { return $ name ; } } return false ; }
|
Get path to requested . scss file
|
7,478
|
protected function getIfModifiedSinceHeader ( ) { $ modifiedSince = null ; if ( isset ( $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE' ] ) ) { $ modifiedSince = $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE' ] ; if ( false !== ( $ semicolonPos = strpos ( $ modifiedSince , ';' ) ) ) { $ modifiedSince = substr ( $ modifiedSince , 0 , $ semicolonPos ) ; } } return $ modifiedSince ; }
|
Get If - Modified - Since header from client request
|
7,479
|
public function checkedCompile ( $ in , $ out ) { if ( ! is_file ( $ out ) || filemtime ( $ in ) > filemtime ( $ out ) ) { $ this -> compileFile ( $ in , $ out ) ; return true ; } return false ; }
|
Check if file need compiling
|
7,480
|
public function cachedCompile ( $ in , $ force = false ) { $ root = null ; if ( is_string ( $ in ) ) { $ root = $ in ; } elseif ( is_array ( $ in ) and isset ( $ in [ 'root' ] ) ) { if ( $ force or ! isset ( $ in [ 'files' ] ) ) { $ root = $ in [ 'root' ] ; } elseif ( isset ( $ in [ 'files' ] ) and is_array ( $ in [ 'files' ] ) ) { foreach ( $ in [ 'files' ] as $ fname => $ ftime ) { if ( ! file_exists ( $ fname ) or filemtime ( $ fname ) > $ ftime ) { $ root = $ in [ 'root' ] ; break ; } } } } else { return null ; } if ( $ root !== null ) { $ out = [ ] ; $ out [ 'root' ] = $ root ; $ out [ 'compiled' ] = $ this -> compileFile ( $ root ) ; $ out [ 'files' ] = $ this -> scss -> getParsedFiles ( ) ; $ out [ 'updated' ] = time ( ) ; return $ out ; } else { return $ in ; } }
|
Execute scssphp on a . scss file or a scssphp cache structure
|
7,481
|
protected function match ( $ regex , & $ out , $ eatWhitespace = null ) { $ r = '/' . $ regex . '/' . $ this -> patternModifiers ; if ( ! preg_match ( $ r , $ this -> buffer , $ out , null , $ this -> count ) ) { return false ; } $ this -> count += strlen ( $ out [ 0 ] ) ; if ( ! isset ( $ eatWhitespace ) ) { $ eatWhitespace = $ this -> eatWhiteDefault ; } if ( $ eatWhitespace ) { $ this -> whitespace ( ) ; } return true ; }
|
Try to match something on head of buffer
|
7,482
|
protected function matchChar ( $ char , $ eatWhitespace = null ) { if ( ! isset ( $ this -> buffer [ $ this -> count ] ) || $ this -> buffer [ $ this -> count ] !== $ char ) { return false ; } $ this -> count ++ ; if ( ! isset ( $ eatWhitespace ) ) { $ eatWhitespace = $ this -> eatWhiteDefault ; } if ( $ eatWhitespace ) { $ this -> whitespace ( ) ; } return true ; }
|
Match a single string
|
7,483
|
protected function mediaQuery ( & $ out ) { $ expressions = null ; $ parts = [ ] ; if ( ( $ this -> literal ( 'only' , 4 ) && ( $ only = true ) || $ this -> literal ( 'not' , 3 ) && ( $ not = true ) || true ) && $ this -> mixedKeyword ( $ mediaType ) ) { $ prop = [ Type :: T_MEDIA_TYPE ] ; if ( isset ( $ only ) ) { $ prop [ ] = [ Type :: T_KEYWORD , 'only' ] ; } if ( isset ( $ not ) ) { $ prop [ ] = [ Type :: T_KEYWORD , 'not' ] ; } $ media = [ Type :: T_LIST , '' , [ ] ] ; foreach ( ( array ) $ mediaType as $ type ) { if ( is_array ( $ type ) ) { $ media [ 2 ] [ ] = $ type ; } else { $ media [ 2 ] [ ] = [ Type :: T_KEYWORD , $ type ] ; } } $ prop [ ] = $ media ; $ parts [ ] = $ prop ; } if ( empty ( $ parts ) || $ this -> literal ( 'and' , 3 ) ) { $ this -> genericList ( $ expressions , 'mediaExpression' , 'and' , false ) ; if ( is_array ( $ expressions ) ) { $ parts = array_merge ( $ parts , $ expressions [ 2 ] ) ; } } $ out = $ parts ; return true ; }
|
Parse media query
|
7,484
|
protected function argValue ( & $ out ) { $ s = $ this -> count ; $ keyword = null ; if ( ! $ this -> variable ( $ keyword ) || ! $ this -> matchChar ( ':' ) ) { $ this -> seek ( $ s ) ; $ keyword = null ; } if ( $ this -> genericList ( $ value , 'expression' ) ) { $ out = [ $ keyword , $ value , false ] ; $ s = $ this -> count ; if ( $ this -> literal ( '...' , 3 ) ) { $ out [ 2 ] = true ; } else { $ this -> seek ( $ s ) ; } return true ; } return false ; }
|
Parse argument value
|
7,485
|
protected function func ( $ name , & $ func ) { $ s = $ this -> count ; if ( $ this -> matchChar ( '(' ) ) { if ( $ name === 'alpha' && $ this -> argumentList ( $ args ) ) { $ func = [ Type :: T_FUNCTION , $ name , [ Type :: T_STRING , '' , $ args ] ] ; return true ; } if ( $ name !== 'expression' && ! preg_match ( '/^(-[a-z]+-)?calc$/' , $ name ) ) { $ ss = $ this -> count ; if ( $ this -> argValues ( $ args ) && $ this -> matchChar ( ')' ) ) { $ func = [ Type :: T_FUNCTION_CALL , $ name , $ args ] ; return true ; } $ this -> seek ( $ ss ) ; } if ( ( $ this -> openString ( ')' , $ str , '(' ) || true ) && $ this -> matchChar ( ')' ) ) { $ args = [ ] ; if ( ! empty ( $ str ) ) { $ args [ ] = [ null , [ Type :: T_STRING , '' , [ $ str ] ] ] ; } $ func = [ Type :: T_FUNCTION_CALL , $ name , $ args ] ; return true ; } } $ this -> seek ( $ s ) ; return false ; }
|
Parse function call
|
7,486
|
protected function argumentList ( & $ out ) { $ s = $ this -> count ; $ this -> matchChar ( '(' ) ; $ args = [ ] ; while ( $ this -> keyword ( $ var ) ) { if ( $ this -> matchChar ( '=' ) && $ this -> expression ( $ exp ) ) { $ args [ ] = [ Type :: T_STRING , '' , [ $ var . '=' ] ] ; $ arg = $ exp ; } else { break ; } $ args [ ] = $ arg ; if ( ! $ this -> matchChar ( ',' ) ) { break ; } $ args [ ] = [ Type :: T_STRING , '' , [ ', ' ] ] ; } if ( ! $ this -> matchChar ( ')' ) || ! $ args ) { $ this -> seek ( $ s ) ; return false ; } $ out = $ args ; return true ; }
|
Parse function call argument list
|
7,487
|
protected function mixedKeyword ( & $ out ) { $ parts = [ ] ; $ oldWhite = $ this -> eatWhiteDefault ; $ this -> eatWhiteDefault = false ; for ( ; ; ) { if ( $ this -> keyword ( $ key ) ) { $ parts [ ] = $ key ; continue ; } if ( $ this -> interpolation ( $ inter ) ) { $ parts [ ] = $ inter ; continue ; } break ; } $ this -> eatWhiteDefault = $ oldWhite ; if ( ! $ parts ) { return false ; } if ( $ this -> eatWhiteDefault ) { $ this -> whitespace ( ) ; } $ out = $ parts ; return true ; }
|
Parse keyword or interpolation
|
7,488
|
protected function variable ( & $ out ) { $ s = $ this -> count ; if ( $ this -> matchChar ( '$' , false ) && $ this -> keyword ( $ name ) ) { $ out = [ Type :: T_VARIABLE , $ name ] ; return true ; } $ this -> seek ( $ s ) ; return false ; }
|
Parse a variable
|
7,489
|
protected function end ( ) { if ( $ this -> matchChar ( ';' ) ) { return true ; } if ( $ this -> count === strlen ( $ this -> buffer ) || $ this -> buffer [ $ this -> count ] === '}' ) { return true ; } return false ; }
|
Consume an end of statement delimiter
|
7,490
|
public static function encode ( $ value ) { $ encoded = '' ; $ vlq = self :: toVLQSigned ( $ value ) ; do { $ digit = $ vlq & self :: VLQ_BASE_MASK ; $ vlq >>= self :: VLQ_BASE_SHIFT ; if ( $ vlq > 0 ) { $ digit |= self :: VLQ_CONTINUATION_BIT ; } $ encoded .= Base64 :: encode ( $ digit ) ; } while ( $ vlq > 0 ) ; return $ encoded ; }
|
Returns the VLQ encoded value .
|
7,491
|
public static function decode ( $ str , & $ index ) { $ result = 0 ; $ shift = 0 ; do { $ c = $ str [ $ index ++ ] ; $ digit = Base64 :: decode ( $ c ) ; $ continuation = ( $ digit & self :: VLQ_CONTINUATION_BIT ) != 0 ; $ digit &= self :: VLQ_BASE_MASK ; $ result = $ result + ( $ digit << $ shift ) ; $ shift = $ shift + self :: VLQ_BASE_SHIFT ; } while ( $ continuation ) ; return self :: fromVLQSigned ( $ result ) ; }
|
Decodes VLQValue .
|
7,492
|
public function scopeAdmins ( $ query , $ paginate = false ) { if ( $ paginate ) { return $ query -> where ( 'ticketit_admin' , '1' ) -> paginate ( $ paginate , [ '*' ] , 'admins_page' ) ; } else { return $ query -> where ( 'ticketit_admin' , '1' ) -> get ( ) ; } }
|
list of all admins and returning collection .
|
7,493
|
public function scopeAgentsLists ( $ query ) { if ( version_compare ( app ( ) -> version ( ) , '5.2.0' , '>=' ) ) { return $ query -> where ( 'ticketit_agent' , '1' ) -> pluck ( 'name' , 'id' ) -> toArray ( ) ; } else { return $ query -> where ( 'ticketit_agent' , '1' ) -> lists ( 'name' , 'id' ) -> toArray ( ) ; } }
|
list of all agents and returning lists array of id and name .
|
7,494
|
public static function isAgent ( $ id = null ) { if ( isset ( $ id ) ) { $ user = User :: find ( $ id ) ; if ( $ user -> ticketit_agent ) { return true ; } return false ; } if ( auth ( ) -> check ( ) ) { if ( auth ( ) -> user ( ) -> ticketit_agent ) { return true ; } } }
|
Check if user is agent .
|
7,495
|
public static function isAssignedAgent ( $ id ) { if ( auth ( ) -> check ( ) && Auth :: user ( ) -> ticketit_agent ) { if ( Auth :: user ( ) -> id == Ticket :: find ( $ id ) -> agent -> id ) { return true ; } } }
|
Check if user is the assigned agent for a ticket .
|
7,496
|
public static function isTicketOwner ( $ id ) { if ( auth ( ) -> check ( ) ) { if ( auth ( ) -> user ( ) -> id == Ticket :: find ( $ id ) -> user -> id ) { return true ; } } }
|
Check if user is the owner for a ticket .
|
7,497
|
public function addAgents ( $ user_ids ) { $ users = Agent :: find ( $ user_ids ) ; foreach ( $ users as $ user ) { $ user -> ticketit_agent = true ; $ user -> save ( ) ; $ users_list [ ] = $ user -> name ; } return $ users_list ; }
|
Assign users as agents .
|
7,498
|
public function removeAgent ( $ id ) { $ agent = Agent :: find ( $ id ) ; $ agent -> ticketit_agent = false ; $ agent -> save ( ) ; if ( version_compare ( app ( ) -> version ( ) , '5.2.0' , '>=' ) ) { $ agent_cats = $ agent -> categories -> pluck ( 'id' ) -> toArray ( ) ; } else { $ agent_cats = $ agent -> categories -> lists ( 'id' ) -> toArray ( ) ; } $ agent -> categories ( ) -> detach ( $ agent_cats ) ; return $ agent ; }
|
Remove user from the agents .
|
7,499
|
public function syncAgentCategories ( $ id , Request $ request ) { $ form_cats = ( $ request -> input ( 'agent_cats' ) == null ) ? [ ] : $ request -> input ( 'agent_cats' ) ; $ agent = Agent :: find ( $ id ) ; $ agent -> categories ( ) -> sync ( $ form_cats ) ; }
|
Sync Agent categories with the selected categories got from update form .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.