/includes/functions.php

Description

Core Functions that can be used by any page in PGV

The functions in this file are common to all PGV pages and include date conversion routines and sorting functions.

phpGedView: Genealogy Viewer Copyright (C) 2002 to 2003 John Finlay and Others

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

  • version: $Id: functions.php 981 2007-03-21 13:24:38Z fisharebest $
Includes
require ("includes/functions.extra.php") (line 3487)
require_once ('includes/mutex_class.php') (line 34)

Core Functions that can be used by any page in PGV

The functions in this file are common to all PGV pages and include date conversion routines and sorting functions.

phpGedView: Genealogy Viewer Copyright (C) 2002 to 2003 John Finlay and Others

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

  • version: $Id: functions.php 981 2007-03-21 13:24:38Z fisharebest $
require_once ('includes/media_class.php') (line 35)
Functions
add_ancestors (line 2965)
void add_ancestors ( $pid, [ $children = false], [ $generations = -1], [ $show_empty = false])
  • $pid
  • $children
  • $generations
  • $show_empty
add_descendancy (line 3050)
void add_descendancy ( $pid, [ $parents = false], [ $generations = -1])
  • $pid
  • $parents
  • $generations
CheckPageViews (line 3104)

check if the page view rate for a session has been exeeded.

void CheckPageViews ()
check_db (line 54)

initialize and check the database

this function will create a database connection and return false if any errors occurred

  • return: true if database successfully connected, false if there was an error
boolean check_db ([boolean $ignore_previous = false])
  • boolean $ignore_previous: whether or not to ignore a previous connection , this parameter is used mainly for the editconfig.php page when setting everything up
check_in (line 3259)

check file in

  • return: whether the file was checked in
boolean check_in (string $logline, string $filename, string $dirname, [boolean $bInsert = false])
  • string $logline: Log message
  • string $filename: Filename
  • string $dirname: Directory
  • boolean $bInsert: Insert Log message
clean_input (line 2799)

clean up user submitted input before submitting it to the SQL query

This function will take user submitted input string and remove any special characters before they are submitted to the SQL query. Examples of invalid characters are _ & ?

  • return: The cleaned up string
string clean_input (string $pid)
  • string $pid: The string to cleanup
compareStrings (line 1216)
void compareStrings ( $aName,  $bName, [ $ignoreCase = true])
  • $aName
  • $bName
  • $ignoreCase
compare_date (line 1966)

fact date sort

compare individuals by a fact date

void compare_date ( $a,  $b)
  • $a
  • $b
compare_facts (line 1686)

compare two fact records by date

Compare facts function is used by the usort PHP function to sort fact baseds on date it parses out the year and if the year is the same, it creates a timestamp based on the current year and the month and day information of the fact

  • return: -1 if $a should be sorted first, 0 if they are the same, 1 if $b should be sorted first
int compare_facts (mixed $a, mixed $b)
  • mixed $a: an array with the fact record at index 1 or just a string with the factrecord
  • mixed $b: an array with the fact record at index 1 or just a string with the factrecord
compare_fact_type (line 1550)
void compare_fact_type ( $afact,  $bfact)
  • $afact
  • $bfact
extract_filename (line 1072)

get the relative filename for a media item

gets the relative file path from the full media path for a media item. checks the $MEDIA_DIRECTORY_LEVELS to make sure the directory structure is maintained.

  • return: a relative path that can be appended to the $MEDIA_DIRECTORY to reference the item
string extract_filename (string $fullpath)
  • string $fullpath: the full path from the media record
extract_fullpath (line 1054)

get the full file path

get the file path from a multimedia gedcom record

  • return: fullpath from the FILE record
the extract_fullpath (string $mediarec)
  • string $mediarec: a OBJE subrecord
factsort (line 1199)

Function to sort GEDCOM fact tags based on their tanslations

void factsort ( $a,  $b)
  • $a
  • $b
filename_decode (line 2638)

decode a filename

windows doesn't use UTF-8 for its file system so we have to decode the filename before it can be used on the filesystem

void filename_decode ( $filename)
  • $filename
filename_encode (line 2650)

encode a filename

windows doesn't use UTF-8 for its file system so we have to encode the filename before it can be used in PGV

void filename_encode ( $filename)
  • $filename
file_is_writeable (line 318)
void file_is_writeable ( $file)
  • $file
find_children (line 779)

find the children in a family

find and return an array containing the children of the given family record

  • author: John Finlay (yalnifj)
array find_children (string $famid, [string $me = ''])
  • string $famid: the gedcom xref id for the family
  • string $me: an xref id of a child to ignore, useful when you want to get a person's siblings but do want to include them as well
find_children_in_record (line 803)

find the children in a family record

find and return an array containing the children of the given family record

  • author: John Finlay (yalnifj)
array find_children_in_record (string $famrec, [string $me = ''])
  • string $famrec: the gedcom record of the family to search in
  • string $me: an xref id of a child to ignore, useful when you want to get a person's siblings but do want to include them as well
find_families_in_record (line 856)

find all family ids in the given record

searches an individual gedcom record and returns an array of the FAMS|C ids

  • return: array of family ids
array find_families_in_record (string $indirec, string $tag)
  • string $indirec: the gedcom record for the person to look in
  • string $tag: The family tag to look for
find_family_ids (line 825)

find all child family ids

searches an individual gedcom record and returns an array of the FAMC ids where this person is a child in the family

  • return: array of family ids
array find_family_ids (string $pid)
  • string $pid: the gedcom xref id for the person to look in
find_highlighted_object (line 954)

find the highlighted media object for a gedcom entity

Rules for finding the highlighted media object:

  1. The first _THUM Y object will be used regardless of the object's level in the gedcom record
  2. The first _PRIM Y object will be used if no _THUM Y exists regardless of level in gedcom record
  3. The first level 1 object will be used if there is no _THUM Y or _PRIM Y and if its doesn't have _THUM N or _PRIM N (level 1 objects appear on the media tab on the individual page)
  4. Adding _PRIM N to any object will cause it not to be shown as a highlighted media.

  • return: an object array with indexes "thumb" and "file" for thumbnail and filename
array find_highlighted_object (string $pid, string $indirec)
  • string $pid: the individual, source, or family id
  • string $indirec: the gedcom record to look in
find_parents (line 733)

find the parents in a family

find and return a two element array containing the parents of the given family record

  • return: returns a two element array with indexes HUSB and WIFE for the parent ids
  • author: John Finlay (yalnifj)
array find_parents (string $famid)
  • string $famid: the gedcom xref id for the family
find_parents_in_record (line 755)

find the parents in a family record

find and return a two element array containing the parents of the given family record

  • return: returns a two element array with indexes HUSB and WIFE for the parent ids
  • author: John Finlay (yalnifj)
array find_parents_in_record (string $famrec)
  • string $famrec: the gedcom record of the family to search in
find_record_in_file (line 875)

find record in file

this function finds a gedcom record in the gedcom file by searching through the file 4Kb at a time

void find_record_in_file (string $gid)
  • string $gid: the gedcom xref id of the record to find
find_sfamily_ids (line 841)

find all spouse family ids

searches an individual gedcom record and returns an array of the FAMS ids where this person is a spouse in the family

  • return: array of family ids
array find_sfamily_ids (string $pid)
  • string $pid: the gedcom xref id for the person to look in
find_updated_record (line 926)

find and return an updated gedcom record

void find_updated_record (string $gid, [string $gedfile = ""])
  • string $gid: the id of the record to find
  • string $gedfile: the gedcom file to get the record from.. defaults to currently active gedcom
gedcomsort (line 1978)
void gedcomsort ( $a,  $b)
  • $a
  • $b
generate_thumbnail (line 1101)

function to generate a thumbnail image

void generate_thumbnail (string $filename, string $thumbnail)
  • string $filename
  • string $thumbnail
getAlphabet (line 2687)
void getAlphabet ()
getfilesize (line 2877)
void getfilesize ( $bytes)
  • $bytes
getmicrotime (line 191)

Get the current time in micro seconds

returns a timestamp for the current time in micro seconds obtained from online documentation for the microtime() function on php.net

  • return: time in micro seconds
float getmicrotime ()
get_all_subrecords (line 478)

find all of the level 1 subrecords of the given record

  • return: an array of the raw subrecords to return
array get_all_subrecords (string $gedrec, [string $ignore = ""], [boolean $families = true], [boolean $sort = true], [boolean $ApplyPriv = true])
  • string $gedrec: the gedcom record to get the subrecords from
  • string $ignore: a list of tags to ignore
  • boolean $families: whether to include any records from the family
  • boolean $sort: whether or not to sort the record by date
  • boolean $ApplyPriv: whether to apply privacy right now or later
get_calendar_fact (line 2478)

format a fact for calendar viewing

  • return: a html text string that can be printed
string get_calendar_fact (string $factrec, string $action,  $filterof, string $pid, [string $filterev = "all"], string $filter)
  • string $factrec: the fact record
  • string $action: tells what type calendar the user is viewing
  • string $filter: should the fact be filtered by living people etc
  • string $pid: the gedcom xref id of the record this fact belongs to
  • string $filterev: "all" to show all events; "bdm" to show only Births, Deaths, Marriages; Event code to show only that event
  • $filterof
get_config_file (line 113)

get gedcom configuration file

this function returns the path to the currently active GEDCOM configuration file

  • return: path to gedcom.ged_conf.php configuration file
string get_config_file ()
get_cont (line 705)

get CONT lines

get the N+1 CONT or CONC lines of a gedcom subrecord

  • return: a string with all CONT or CONC lines merged
string get_cont (int $nlevel, string $nrec, [ $tobr = true])
  • int $nlevel: the level of the CONT lines to get
  • string $nrec: the gedcom subrecord to search in
  • $tobr
get_first_tag (line 399)

Get first tag in GEDCOM sub-record

This routine uses function get_sub_record to retrieve the specified sub-record and then returns the first tag.

void get_first_tag ( $level,  $tag,  $gedrec, [ $num = 1])
  • $level
  • $tag
  • $gedrec
  • $num
get_gedcom_from_id (line 274)

get a gedcom filename from its database id

string get_gedcom_from_id (int $ged_id)
  • int $ged_id: The gedcom database id to get the filename for
get_gedcom_value (line 566)

get gedcom tag value

returns the value of a gedcom tag from the given gedcom record

string get_gedcom_value (string $tag, int $level, string $gedrec, [int $truncate = ''], [boolean $convert = true])
  • string $tag: The tag to find, use : to delineate subtags
  • int $level: The gedcom line level of the first tag to find, setting level to 0 will cause it to use 1+ the level of the incoming record
  • string $gedrec: The gedcom record to get the value from
  • int $truncate: Should the value be truncated to a certain number of characters
  • boolean $convert: Should data like dates be converted using the configuration settings
get_new_xref (line 3130)

get the next available xref

calculates the next available XREF id for the given type of record

string get_new_xref ([string $type = 'INDI'], [ $use_cache = false])
  • string $type: the type of record, defaults to 'INDI'
  • $use_cache
get_privacy_file (line 159)

Get the path to the privacy file

Get the path to the privacy file for the currently active GEDCOM

  • return: path to the privacy file
string get_privacy_file ()
get_privacy_file_version (line 138)

Get the version of the privacy file

This function opens the given privacy file and returns the privacy version from the file

  • return: the privacy file version number
string get_privacy_file_version (string $privfile)
  • string $privfile: the path to the privacy file
get_query_string (line 2938)

function to build an URL querystring from GET or POST variables

string get_query_string ()
get_relationship (line 2000)

Get relationship between two individuals in the gedcom

function to calculate the relationship between two people it uses hueristics based on the individuals birthdate to try and calculate the shortest path between the two individuals it uses a node cache to help speed up calculations when using relationship privacy this cache is indexed using the string "$pid1-$pid2"

void get_relationship (string $pid1, string $pid2, [bool $followspouse = true], [ $maxlength = 0], [bool $ignore_cache = false], [int $path_to_find = 0], int $maxlenght)
  • string $pid1: the ID of the first person to compute the relationship from
  • string $pid2: the ID of the second person to compute the relatiohip to
  • bool $followspouse: whether to add spouses to the path
  • int $maxlenght: the maximim length of path
  • bool $ignore_cache: enable or disable the relationship cache
  • int $path_to_find: which path in the relationship to find, 0 is the shortest path, 1 is the next shortest path, etc
  • $maxlength
get_report_list (line 2717)

get a list of the reports in the reports directory

When $force is false, the function will first try to read the reports list from the$INDEX_DIRECTORY."/reports.dat" data file. Otherwise the function will parse the report xml files and get the titles.

  • return: The array of the found reports with indexes [title] [file]
array get_report_list ([boolean $force = false])
  • boolean $force: force the code to look in the directory and parse the files again
get_sub_record (line 429)

get a gedcom subrecord

searches a gedcom record and returns a subrecord of it. A subrecord is defined starting at a line with level N and all subsequent lines greater than N until the next N level is reached. For example, the following is a BIRT subrecord:

  1. BIRT
  2.  DATE JAN 1900
  3.  PLAC PhoenixMaricopaArizona
The following example is the DATE subrecord of the above BIRT subrecord:
  1. DATE JAN 1900

  • return: the subrecord that was found or an empty string "" if not found.
  • author: John Finlay (yalnifj)
  • author: Roland Dalmulder (roland-d)
string get_sub_record (int $level, string $tag, string $gedrec, [int $num = 1])
  • int $level: the N level of the subrecord to get
  • string $tag: a gedcom tag or string to search for in the record (ie 1 BIRT or 2 DATE)
  • string $gedrec: the parent gedcom record to search in
  • int $num: this allows you to specify which matching $tag to get. Oftentimes a gedcom record will have more that 1 of the same type of subrecord. An individual may have multiple events for example. Passing $num=1 would get the first 1. Passing $num=2 would get the second one, etc.
get_theme_names (line 2448)

get theme names

function to get the names of all of the themes as an array it searches the themes directory and reads the name from the theme_name variable in the theme.php file.

  • return: and array of theme names and their corresponding directory
array get_theme_names ()
has_utf8 (line 3212)

check if the given string has UTF-8 characters

void has_utf8 ( $string)
  • $string
idsort (line 1531)

sort a list by the gedcom xref id

  • return: negative numbers sort $a first, positive sort $b first
int idsort (array $a, array $b)
  • array $a: the first $indi array to sort on
  • array $b: the second $indi array to sort on
id_type (line 3229)

Determine the type of ID NOTE: Be careful when using this function as not all GEDCOMS have ID prefixes. Many GEDCOMS just use numbers like 100, 101, etc without the I, F, etc prefixes.

void id_type (string $id)
  • string $id
is_dead_id (line 293)

Check if a person is dead

For the given XREF id, this function will return true if the person is dead and false if the person is alive.

  • return: True if dead, false if alive
boolean is_dead_id (string $pid)
  • string $pid: The Gedcom XREF ID of the person to check
itemsort (line 1485)

sort arrays or strings

this function is called by the uasort PHP function to compare two items and tell which should be sorted first. It uses the language alphabets to create a string that will is used to compare the strings. For each letter in the strings, the letter's position in the alphabet string is found. Whichever letter comes first in the alphabet string should be sorted first.

  • return: negative numbers sort $a first, positive sort $b first
int itemsort (array $a, array $b)
  • array $a: first item
  • array $b: second item
lettersort (line 1546)
void lettersort ( $a,  $b)
  • $a
  • $b
loadLanguage (line 3298)

Load language variables Set language-dependent global variables

This function loads the variables for the language, as specified by the first input parameter. It also loads any existing language-specific functions such special date handling for Finnish and Turkish.

If the forceLoad parameter is true, English will be loaded first, followed by the desired language file.

void loadLanguage ([ $desiredLanguage = "english"], [ $forceLoad = false])
  • $desiredLanguage
  • $forceLoad
mediasort (line 1506)

sort an array of media items

void mediasort ( $a,  $b)
  • $a
  • $b
pgv_array_merge (line 2927)

array merge function for PGV

the PHP array_merge function will reindex all numerical indexes This function should only be used for associative arrays

void pgv_array_merge (array $array1, array $array2)
  • array $array1
  • array $array2
pgv_error_handler (line 335)

PGV Error Handling function

This function will be called by PHP whenever an error occurs. The error handling is set in the session.php

void pgv_error_handler ( $errno,  $errstr,  $errfile,  $errline)
  • $errno
  • $errstr
  • $errfile
  • $errline
remove_custom_tags (line 2810)

remove any custom PGV tags from the given gedcom record

custom tags include _PGVU and _THUM

  • return: the updated gedcom record
string remove_custom_tags (string $gedrec, [ $remove = "no"])
  • string $gedrec: the raw gedcom record
  • $remove
runHooks (line 2833)

Locate and run any hook files found.

  • return: array containing any results from the hooks (not currently used)
  • todo: add aditional types, including search.
  • author: Patrick Kellum
array runHooks (string $type, [array $params = array()])
  • string $type: the type of hook requested (login|logout|adduser|updateuser|deleteuser|getuser)
  • array $params: array of parameters
sort_facts (line 1870)

This function will sort a list of facts It uses an insertion sort algorithm which is a slower algorithm but it insures that all of the items get checked against each other which works better with the way that facts are sorted.

New twist: Run the sort twice, first on dated material, then undated, inserting at the last position that matches sort order.

void sort_facts ( &$factlist, $array $factlist)
  • $array $factlist: the array of facts to sort
  • &$factlist
splitkey (line 2910)

split multi-ged keys and return either key or gedcom

  • return: either the key or the gedcom name
string splitkey (string $key, string $type)
  • string $key: the multi-ged key to be split
  • string $type: either "id" or "ged", depending on what must be returned
store_gedcoms (line 204)

Store GEDCOMS array

this function will store the $GEDCOMS array in the $INDEX_DIRECTORY/gedcoms.php file. The gedcoms.php file is included in session.php to create the $GEDCOMS array with every page request.

void store_gedcoms ()
stringsort (line 1210)

String sorting function

  • return: negative numbers sort $a first, positive sort $b first
int stringsort ( $aName,  $bName, string $a, string $b)
  • string $a
  • string $b
  • $aName
  • $bName
stringsort2 (line 1213)
void stringsort2 ( $aName,  $bName)
  • $aName
  • $bName
strrpos4 (line 384)

Replacement function for strrpos() Returns the numeric position of the last occurrence of needle in the haystack string.

Note that the needle in this case can only be a single character in PHP 4. If a string is passed as the needle, then only the first character of that string will be used.

  • author: escii at hotmail dot com ( Brendan )
void strrpos4 (string $haystack, string $needle, int $ret)
  • string $haystack: The text to be searched through
  • string $needle: The text to be found
  • int $ret: The position at which the needle is found
usersort (line 1456)

User Name comparison Function

This function just needs to call the itemsort function on the fullname field of the array

  • return: negative numbers sort $a first, positive sort $b first
int usersort (array $a, array $b)
  • array $a: first user array
  • array $b: second user array
write_changes (line 2388)

write changes

this function writes the $pgv_changes back to the $INDEX_DIRECTORY/pgv_changes.php file so that it can be read in and checked to see if records have been updated. It also stores old records so that they can be undone.

  • return: true if successful false if there was an error
bool write_changes ()

Documentation generated on Wed, 28 Mar 2007 09:54:16 -0600 by phpDocumentor 1.3.1