1) {
$text = "";
foreach ($lines as $indexval => $line) $text .= split_align_text($line, $maxlen)."\n";
return $text;
}
// process current line word by word
$split = explode(" ", $data);
$text = "";
$line = "";
// do not split hebrew line
$found = false;
foreach ($RTLOrd as $indexval => $ord) {
if (strpos($data, chr($ord)) !== false) $found=true;
}
if ($found) $line=$data;
else
foreach ($split as $indexval => $word) {
$len = strlen($line);
//if (!empty($line) and ord($line{0})==215) $len/=2; // hebrew text
$wlen = strlen($word);
// line too long ?
if (($len+$wlen)<$maxlen) {
if (!empty($line)) $line .= " ";
$line .= "$word";
}
else {
$p = max(0,floor(($maxlen-$len)/2));
if (!empty($line)) {
$line = str_repeat(" ", $p) . "$line"; // center alignment using spaces
$text .= "$line\n";
}
$line = $word;
}
}
// last line
if (!empty($line)) {
$len = strlen($line);
if (in_array(ord($line{0}),$RTLOrd)) $len/=2;
$p = max(0,floor(($maxlen-$len)/2));
$line = str_repeat(" ", $p) . "$line"; // center alignment using spaces
$text .= "$line";
}
return $text;
}
/**
* print ancestors on a fan chart
*
* @param array $treeid ancestry pid
* @param int $fanw fan width in px (default=640)
* @param int $fandeg fan size in deg (default=270)
*/
function print_fan_chart($treeid, $fanw=640, $fandeg=270) {
global $PEDIGREE_GENERATIONS, $fan_width, $fan_style, $name, $TEXT_DIRECTION;
global $WT_IMAGES, $GEDCOM, $fanChart;
// check for GD 2.x library
if (!defined("IMG_ARC_PIE")) {
echo "".i18n::translate('PHP server misconfiguration: GD 2.x library required to use image functions.')."";
echo "
";
return false;
}
if (!function_exists("ImageTtfBbox")) {
echo "".i18n::translate('PHP server misconfiguration: FreeType library required to use TrueType fonts.')."";
echo "
";
return false;
}
// Validate
if (!file_exists($fanChart['font'])) {
echo '', i18n::translate('Font file not found on PHP server'), ' : ', $fanChart['font']. '';
return false;
}
$fanChart['size'] = intval($fanChart['size']);
if ($fanChart['size']<2) $fanChart['size'] = 7;
if (empty($fanChart['color']) || $fanChart['color']{0}!='#') $fanChart['color'] = '#000000';
if (empty($fanChart['bgColor']) || $fanChart['bgColor']{0}!='#') $fanChart['bgColor'] = '#EEEEEE';
if (empty($fanChart['bgMColor']) || $fanChart['bgMColor']{0}!='#') $fanChart['bgMColor'] = '#D0D0AC';
if (empty($fanChart['bgFColor']) || $fanChart['bgFColor']{0}!='#') $fanChart['bgFColor'] = '#D0ACD0';
$treesize=count($treeid);
if ($treesize<1) return;
// generations count
$gen=log($treesize)/log(2)-1;
$sosa=$treesize-1;
// fan size
if ($fandeg==0) $fandeg=360;
$fandeg=min($fandeg, 360);
$fandeg=max($fandeg, 90);
$cx=$fanw/2-1; // center x
$cy=$cx; // center y
$rx=$fanw-1;
$rw=$fanw/($gen+1);
$fanh=$fanw; // fan height
if ($fandeg==180) $fanh=round($fanh*($gen+1)/($gen*2));
if ($fandeg==270) $fanh=round($fanh*.86);
$scale=$fanw/640;
// image init
$image = ImageCreate($fanw, $fanh);
$black = ImageColorAllocate($image, 0, 0, 0);
$white = ImageColorAllocate($image, 0xFF, 0xFF, 0xFF);
ImageFilledRectangle ($image, 0, 0, $fanw, $fanh, $white);
ImageColorTransparent($image, $white);
$color = ImageColorAllocate($image, hexdec(substr($fanChart['color'],1,2)), hexdec(substr($fanChart['color'],3,2)), hexdec(substr($fanChart['color'],5,2)));
$bgcolor = ImageColorAllocate($image, hexdec(substr($fanChart['bgColor'],1,2)), hexdec(substr($fanChart['bgColor'],3,2)), hexdec(substr($fanChart['bgColor'],5,2)));
$bgcolorM = ImageColorAllocate($image, hexdec(substr($fanChart['bgMColor'],1,2)), hexdec(substr($fanChart['bgMColor'],3,2)), hexdec(substr($fanChart['bgMColor'],5,2)));
$bgcolorF = ImageColorAllocate($image, hexdec(substr($fanChart['bgFColor'],1,2)), hexdec(substr($fanChart['bgFColor'],3,2)), hexdec(substr($fanChart['bgFColor'],5,2)));
// imagemap
$imagemap="";
echo $imagemap;
ImageStringUp($image, 1, $fanw-10, $fanh/3, WT_SERVER_NAME.WT_SCRIPT_PATH, $color);
// here we cannot send image to browser ('header already sent')
// and we dont want to use a tmp file
// step 1. save image data in a session variable
ob_start();
ImagePng($image);
$image_data = ob_get_contents();
ob_end_clean();
$image_data = serialize($image_data);
unset ($_SESSION['image_data']);
$_SESSION['image_data']=$image_data;
// step 2. call imageflush.php to read this session variable and display image
// note: arg "image_name=" is to avoid image miscaching
$image_name= "V".time();
unset($_SESSION[$image_name]); // statisticsplot.php uses this to hold a file name to send to browser
$image_title=preg_replace("~<.*>~", "", $name) . " " . i18n::translate('Circle diagram');
echo "
";
echo "";
echo "
";
echo "" . i18n::translate('Circle diagram') . ":";
echo "";
// -- print the form to change the number of displayed generations
echo WT_JS_START;
echo "var pastefield; function paste_id(value) { pastefield.value=value; }";
echo WT_JS_END;
echo " | "; echo " |