function UTF8_wordwrap($text, $width = 75, $break = "\n", $cut = FALSE) { if ($width <= 0) { $width = 75; } if (is_string($text) && strlen($text) <= $width) { return $text; } // Nothing to do if ($break == '') { $break = "\n"; } $UTF8_text = UTF8_str_split($text); $UTF8_break = UTF8_str_split($break); $UTF8_result = array(); while (UTF8_strlen($UTF8_text) > $width) { $longWord = FALSE; for ($i = $width; $i >= 0; $i--) { if ($UTF8_text[$i] == ' ') { break; } } if ($i < 0) { // We're dealing with a very long word // Not too sure what $cut is supposed to accomplish -- we'll just chop the word $longWord = TRUE; // This means: "not wrapping at a space" $i = $width; } $thisPiece = array_slice($UTF8_text, 0, $i); foreach ($thisPiece as $char) { // Copy front part of input string $UTF8_result[] = $char; } foreach ($UTF8_break as $char) { // Copy separator string $UTF8_result[] = $char; } if (!$longWord) { $i++; } // Skip space at end of piece we've just worked on $UTF8_text = UTF8_substr($UTF8_text, $i); // Remove that piece } foreach ($UTF8_text as $char) { // Copy remainder of input string $UTF8_result[] = $char; } if (is_array($text)) { return $UTF8_result; } return implode('', $UTF8_result); }
function _addName($type, $value, $gedrec) { global $pgv_lang; if (UTF8_strlen($value) < 100) { parent::_addName($type, $value, $gedrec); } else { parent::_addName($type, UTF8_substr($value, 0, 100) . $pgv_lang["ellipsis"], $gedrec); } }
/** * builds and returns sosa relationship name in the active language * * @param string $sosa sosa number */ function get_sosa_name($sosa) { global $LANGUAGE, $pgv_lang; if ($sosa < 2) { return ""; } $sosaname = ""; $sosanr = floor($sosa / 2); $gen = floor(log($sosanr) / log(2)); // first try a generic algorithm, this is later overridden // by language specific algorithms. if (!empty($pgv_lang["sosa_{$sosa}"])) { $sosaname = $pgv_lang["sosa_{$sosa}"]; } else { if ($gen > 2) { switch ($LANGUAGE) { case "danish": case "norwegian": case "swedish": $sosaname = ""; $addname = ""; $father = UTF8_strtolower($pgv_lang["father"]); $mother = UTF8_strtolower($pgv_lang["mother"]); $grand = "be" . ($LANGUAGE == "danish" ? "dste" : "ste"); $great = "olde"; $tip = "tip" . ($LANGUAGE == "danish" ? "-" : "p-"); for ($i = $gen; $i > 2; $i--) { $sosaname .= $tip; } if ($gen >= 2) { $sosaname .= $great; } if ($gen == 1) { $sosaname .= $grand; } for ($i = $gen; $i > 0; $i--) { if (!(floor($sosa / pow(2, $i)) % 2)) { $addname .= $father; } else { $addname .= $mother; } if ($gen % 2 && !($i % 2) || !($gen % 2) && $i % 2) { $addname .= "s "; } } if ($LANGUAGE == "swedish") { $sosaname = $addname; } if ($sosa % 2 == 0) { $sosaname .= $father; if ($gen > 0) { $addname .= $father; } } else { $sosaname .= $mother; if ($gen > 0) { $addname .= $mother; } } $sosaname = UTF8_str_split($sosaname); $sosaname[0] = UTF8_strtoupper($sosaname[0]); $sosaname = implode('', $sosaname); if ($LANGUAGE != "swedish") { if (!empty($addname)) { $sosaname .= ($gen > 5 ? "<br /> " : "") . " <small>(" . $addname . ")</small>"; } } break; case "dutch": // reference: http://nl.wikipedia.org/wiki/Voorouder // Our numbers are 2 less than those shown in the article. We number parents // as generation zero where the article numbers them as generation 2. $sosaname = ""; // Please leave the following strings untranslated if ($gen & 512) { break; } // 512 or higher if ($gen & 256) { $sosaname .= "hoog"; } // 256 to 511 if ($gen & 128) { $sosaname .= "opper"; } // 128 to 511 if ($gen & 64) { $sosaname .= "aarts"; } // 64 to 511 if ($gen & 32) { $sosaname .= "voor"; } // 32 to 511 if ($gen & 16) { $sosaname .= "edel"; } // 16 to 511 if ($gen & 8) { $sosaname .= "stam"; } // 8 to 511 if ($gen & 4) { $sosaname .= "oud"; } // 4 to 511 $gen = $gen & 3; if ($gen == 3) { $sosaname .= "betovergroot"; } if ($gen == 2) { $sosaname .= "overgroot"; } if ($gen == 1) { $sosaname .= "groot"; } if ($sosa % 2 == 0) { $sosaname .= $pgv_lang["father"]; } else { $sosaname .= $pgv_lang["mother"]; } $sosaname = strtolower($sosaname); break; case "finnish": $sosaname = ""; $father = UTF8_strtolower($pgv_lang["father"]); $mother = UTF8_strtolower($pgv_lang["mother"]); // $father = "isä"; // $mother = "äiti"; // $pgv_lang["sosa_2"]= "äidin"; //Grand (mother) for ($i = $gen; $i > 0; $i--) { if (!(floor($sosa / pow(2, $i)) % 2)) { $sosaname .= $father . "n"; } else { $sosaname .= UTF8_substr($mother, 0, 2) . "din"; } } if ($sosa % 2 == 0) { $sosaname .= $father; } else { $sosaname .= $mother; } $sosaname = UTF8_str_split($sosaname); $sosaname[0] = UTF8_strtoupper($sosaname[0]); $sosaname = implode('', $sosaname); break; case "hebrew": $sosaname = ""; $addname = ""; $father = $pgv_lang["father"]; $mother = $pgv_lang["mother"]; $greatf = $pgv_lang["sosa_22"]; $greatm = $pgv_lang["sosa_21"]; $of = $pgv_lang["sosa_23"]; $grandfather = $pgv_lang["sosa_4"]; $grandmother = $pgv_lang["sosa_5"]; // $father = "Aba"; // $mother = "Ima"; // $grandfather = "Saba"; // $grandmother = "Savta"; // $greatf = " raba"; // $greatm = " rabta"; // $of = " shel "; for ($i = $gen; $i >= 0; $i--) { if ($i == 0) { if (!($sosa % 2)) { $addname .= "f"; } else { $addname .= "m"; } } else { if (!(floor($sosa / pow(2, $i)) % 2)) { $addname .= "f"; } else { $addname .= "m"; } } if ($i == 0 || strlen($addname) == 3) { if (strlen($addname) == 3) { if (substr($addname, 2, 1) == "f") { $addname = $grandfather . $greatf; } else { $addname = $grandmother . $greatm; } } else { if (strlen($addname) == 2) { if (substr($addname, 1, 1) == "f") { $addname = $grandfather; } else { $addname = $grandmother; } } else { if ($addname == "f") { $addname = $father; } else { $addname = $mother; } } } $sosaname = $addname . ($i < $gen - 2 ? $of : "") . $sosaname; $addname = ""; } } break; default: $paternal = floor($sosa / pow(2, $gen)) == 2 ? "paternal" : "maternal"; $male = $sosa % 2 == 0 ? "male" : "female"; if (!empty($pgv_lang["sosa_{$paternal}_{$male}_n_generations"])) { $sosaname = sprintf($pgv_lang["sosa_{$paternal}_{$male}_n_generations"], $gen + 1, $gen, $gen - 1); } } } } if (!empty($sosaname)) { return "{$sosaname}<!-- sosa={$sosa} nr={$sosanr} gen={$gen} -->"; } else { return "<!-- sosa={$sosa} nr={$sosanr} gen={$gen} -->"; } }
static function _commonGivenQuery($sex = 'B', $type = 'list', $show_tot = false, $params = null) { global $TEXT_DIRECTION, $GEDCOM, $TBLPREFIX, $pgv_lang, $gBitDb; static $sort_types = array('count' => 'asort', 'rcount' => 'arsort', 'alpha' => 'ksort', 'ralpha' => 'krsort'); static $sort_flags = array('count' => SORT_NUMERIC, 'rcount' => SORT_NUMERIC, 'alpha' => SORT_STRING, 'ralpha' => SORT_STRING); if (is_array($params) && isset($params[0]) && $params[0] != '' && $params[0] >= 0) { $threshold = strtolower($params[0]); } else { $threshold = 1; } if (is_array($params) && isset($params[1]) && $params[1] != '' && $params[1] >= 0) { $maxtoshow = strtolower($params[1]); } else { $maxtoshow = 10; } if (is_array($params) && isset($params[2]) && $params[2] != '' && isset($sort_types[strtolower($params[2])])) { $sorting = strtolower($params[2]); } else { $sorting = 'rcount'; } switch ($sex) { case 'M': $sex_sql = "i_sex='M'"; break; case 'F': $sex_sql = "i_sex='F'"; break; case 'U': $sex_sql = "i_sex='U'"; break; case 'B': $sex_sql = "i_sex!='U'"; break; } $ged_id = get_id_from_gedcom($GEDCOM); $result = $gBitDb->query("SELECT n_givn, COUNT(*) AS num FROM {$TBLPREFIX}name JOIN {$TBLPREFIX}individuals ON (n_id=i_id AND n_file=i_file) WHERE n_file={$ged_id} AND n_type!='_MARNM' AND n_givn NOT IN ('@P.N.', '') AND LENGTH(n_givn)>1 AND {$sex_sql} GROUP BY n_id, n_givn"); $nameList = array(); while ($row = $result->fetchRow) { // Split "John Thomas" into "John" and "Thomas" and count against both totals foreach (explode(' ', $row[n_givn]) as $given) { $given = str_replace(array('*', '"'), '', $given); if (strlen($given) > 1) { if (array_key_exists($given, $nameList)) { $nameList[$given] += $row[num]; } else { $nameList[$given] = $row[num]; } } } } arsort($nameList, SORT_NUMERIC); $nameList = array_slice($nameList, 0, $maxtoshow); if (count($nameList) == 0) { return ''; } if ($type == 'chart') { return $nameList; } $common = array(); foreach ($nameList as $given => $total) { if ($maxtoshow !== -1) { if ($maxtoshow-- <= 0) { break; } } if ($total < $threshold) { break; } if ($show_tot) { $tot = PrintReady("[{$total}]"); if ($TEXT_DIRECTION == 'ltr') { $totL = ''; $totR = ' ' . $tot; } else { $totL = $tot . ' '; $totR = ''; } } else { $totL = ''; $totR = ''; } switch ($type) { case 'table': $common[] = '<tr><td class="optionbox">' . PrintReady(UTF8_substr($given, 0, 1) . UTF8_strtolower(UTF8_substr($given, 1))) . '</td><td class="optionbox">' . $total . '</td></tr>'; break; case 'list': $common[] = "\t<li>{$totL}" . PrintReady(UTF8_substr($given, 0, 1) . UTF8_strtolower(UTF8_substr($given, 1))) . "{$totR}</li>\n"; break; case 'nolist': $common[] = $totL . PrintReady(UTF8_substr($given, 0, 1) . UTF8_strtolower(UTF8_substr($given, 1))) . $totR; break; } } if ($common) { switch ($type) { case 'table': $lookup = array('M' => $pgv_lang['male'], 'F' => $pgv_lang['female'], 'U' => $pgv_lang['unknown'], 'B' => $pgv_lang['all']); return '<table><tr><td colspan="2" class="descriptionbox center">' . $lookup[$sex] . '</td></tr><tr><td class="descriptionbox center">' . $pgv_lang['names'] . '</td><td class="descriptionbox center">' . $pgv_lang['count'] . '</td></tr>' . join('', $common) . '</table>'; case 'list': return "<ul>\n" . join("\n", $common) . "</ul>\n"; case 'nolist': return join('; ', $common); } } else { return ''; } }
// Fetch a list of the initial letters of all surnames in the database $initials = get_indilist_salpha($SHOW_MARRIED_NAMES, true, PGV_GED_ID); // If there are no individuals in the database, do something sensible if (!$initials) { $initials[] = '@'; } // Make sure selections are consistent. // i.e. can't specify show_all and surname at the same time. if ($show_all == 'yes') { $alpha = ''; $surname = ''; $legend = $pgv_lang['all']; $url = 'famlist.php?show_all=yes'; } elseif ($surname) { $surname = UTF8_strtoupper($surname); $alpha = UTF8_substr($surname, 0, 1); foreach (db_collation_digraphs() as $from => $to) { if (strpos($surname, UTF8_strtoupper($to)) === 0) { $alpha = UTF8_strtoupper($from); } } $show_all = 'no'; $legend = $surname; switch ($falpha) { case '': break; case '@': $legend .= ', ' . $pgv_lang['NN']; break; default: $legend .= ', ' . $falpha;
function get_indilist_galpha($surn, $salpha, $marnm, $fams, $ged_id) { global $TBLPREFIX, $DB_UTF8_COLLATION, $DBCOLLATE, $gBitDb; if ($fams) { $tables = "{$TBLPREFIX}name, {$TBLPREFIX}individuals, {$TBLPREFIX}link"; $join = "n_file={$ged_id} AND i_file=n_file AND i_id=n_id AND l_file=n_file AND l_from=n_id AND l_type='FAMS'"; } else { $tables = "{$TBLPREFIX}name, {$TBLPREFIX}individuals"; $join = "n_file={$ged_id} AND i_file=n_file AND i_id=n_id"; } if ($marnm) { $join .= " AND n_type!='_MARNM'"; } if ($surn) { $join .= " AND n_sort LIKE {$surn}"; } elseif ($salpha) { $join .= " AND n_sort LIKE {$salpha}%"; } if ($DB_UTF8_COLLATION) { $column = "UPPER(SUBSTR(n_givn {$DBCOLLATE}, 1, 1))"; } else { $column = "UPPER(SUBSTR(n_givn {$DBCOLLATE}, 1, 3))"; } $exclude = ''; $include = ''; $digraphs = db_collation_digraphs(); foreach (array_unique($digraphs) as $digraph) { // Multi-character digraphs $exclude .= " AND n_sort NOT LIKE '{$digraph}%' {$DBCOLLATE}"; } foreach ($digraphs as $to => $from) { // Single-character digraphs $include .= " UNION SELECT UPPER('{$to}' {$DBCOLLATE}) AS alpha FROM {$tables} WHERE {$join} AND n_sort LIKE '{$from}%' {$DBCOLLATE} GROUP BY 1"; } $alphas = $gBitDb->getOne("SELECT {$column} AS alpha FROM {$tables} WHERE {$join} {$exclude} GROUP BY 1 {$include} ORDER BY 1"); $list = array(); foreach ($alphas as $alpha) { if ($DB_UTF8_COLLATION) { $letter = $alpha; } else { $letter = UTF8_strtoupper(UTF8_substr($alpha, 0, 1)); } $list[$letter] = $letter; } // If we didn't sort in the DB, sort ourselves if (!$DB_UTF8_COLLATION) { uasort($list, 'stringsort'); } // sorting puts "," and "@" first, so force them to the end if (in_array(',', $list)) { unset($list[',']); $list[','] = ','; } if (in_array('@', $list)) { unset($list['@']); $list['@'] = '@'; } return $list; }