Image text

If you've programmed a new HuMo-genealogy feature (that you'd like to see included in the official version), please upload and describe your work here.
Post Reply
colin
Posts: 48
Joined: Sun 24 Dec 2017, 23:13

Image text

Post by colin »

I made a simple change for the text appearing under the images. It is based on the text in the db being in format of <title>|<description>.
My mod changes the text from <title>|<description> to only <description> (when it exists), else <title>.

In show_picture.php, at about line 213,
change the line
if(isset($picture_text)) {$process_text.='<div class="phototext">'.$picture_text.'</div>';}

to
if(strpos($picture_text,"|",0)) {$picture_text = substr($picture_text,strpos($picture_text,"|",0)+1);}
if(isset($picture_text)) {$process_text.='<div class="phototext">'.$picture_text.'</div>';}

in mainindex_cls.php, at about line 579
change

$fam=''; if ($personmnDb->pers_famc) $fam=$personmnDb->pers_famc; else $fam=$personmnDb->pers_fams;
$text.='<a href="family.php?tree_id='.$personmnDb->pers_tree_id.'&amp;id='.$fam.'&amp;main_person='.$personmnDb->pers_gedcomnumber.'">';
$text.=$picqryDb->event_text;

to
$picture_text='';
$picture_text.=$picqryDb->event_text;
if(strpos($picture_text,"|",0)) {$picture_text = substr($picture_text,strpos($picture_text,"|",0)+1);}

$fam=''; if ($personmnDb->pers_famc) $fam=$personmnDb->pers_famc; else $fam=$personmnDb->pers_fams;
$text.='<a href="family.php?tree_id='.$personmnDb->pers_tree_id.'&amp;id='.$fam.'&amp;main_person='.$personmnDb->pers_gedcomnumber.'">';

// *** $text.=$picqryDb->event_text;
$text.=$picture_text;
User avatar
Huub
HuMo-genealogy programmer
HuMo-genealogy programmer
Posts: 2693
Joined: Wed 27 Aug 2008, 11:34
Location: Heerhugowaard, Netherlands
Contact:

Re: Image text

Post by Huub »

Hi Colin,

Thanks for the code!

I will test this later. It depends per genealogical program if description or title is used in the gedcom export, and in some cases both items are used.
:arrow: HuMo-genealogy update? Backup your database! Editing in HuMo-genealogy? Backup your data!
Make multiple backups with: PHPMyAdmin, gedcom export and database export.

HuMo-genealogy software: http://humo-gen.com
colin
Posts: 48
Joined: Sun 24 Dec 2017, 23:13

Re: Image text

Post by colin »

Huub,

I've updated my code (around glightbox), and added below.
It works whether there is the '|' in the text or not (as I don't always have it). The way it works is:
When text is 'title text|long description text'
On the page it just shows 'title text' under the image, but when the lightbox is brought up, it shows 'description text' under that. This allows for a short title, and avoids, mostly, the scroll bars around the tumb image, keeping that reasonably tidy. When the lightbox image is shown the long description is show. I use it, for example, for a family group photo. When the thumb is shown, it may have 'Fred Smith and family', but the larger lightbox image will have a full description, e.g. 'L-R Jenny, John, Fred, Allan and Joan Smith' (or, even longer over multiple lines.)

Full changes (only a few lines changed in each of the 2 files) below:

In the file include/mainindex_cls.php
in function : function random_photo(){

change to:

function random_photo(){
global $dataDb, $tree_id, $dbh, $db_functions;
$text='';

$tree_pict_path=$dataDb->tree_pict_path; if (substr($tree_pict_path,0,1)=='|') $tree_pict_path='media/';

$qry="SELECT * FROM humo_events
WHERE event_tree_id='".$tree_id."' AND event_kind='picture' AND event_connect_kind='person' AND event_connect_id NOT LIKE ''
ORDER BY RAND()";
$picqry=$dbh->query($qry);
while($picqryDb = $picqry->fetch(PDO::FETCH_OBJ)) {
$picname = str_replace(" ","_",$picqryDb->event_event);
$check_file=strtolower(substr($picname,-3,3));
if (($check_file=='png' OR $check_file=='gif' OR $check_file=='jpg')AND file_exists($tree_pict_path.$picname)){
@$personmnDb = $db_functions->get_person($picqryDb->event_connect_id);
$man_cls = New person_cls;
$man_cls->construct($personmnDb);
$man_privacy=$man_cls->privacy;
if ($man_cls->privacy==''){
$text.='<div style="text-align: center;">';

//$text.='<img src="'.$tree_pict_path.$picname.'" width="200 px"
// style="border-radius: 15px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);"><br>';

// *** Show picture using GLightbox ***

$event1_text=$picqryDb->event_text;

if(strpos($event1_text,"|",0)) {$event1_text = substr($event1_text, strpos($event1_text,"|",0)+1);}

$text.='<a href="'.$tree_pict_path.$picname.'" class="glightbox" data-glightbox="description: '.str_replace("&", "&amp;", $event1_text).'"><img src="'.$tree_pict_path.$picname.'" width="200 px" style="border-radius: 15px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);"></a><br>';



// *** Person url example (I23 optional): http://localhost/humo-genealogy/family/2/F10/I23/ ***
$url=$man_cls->person_url($personmnDb->pers_tree_id,$personmnDb->pers_indexnr,$personmnDb->pers_gedcomnumber);

$event2_text=$picqryDb->event_text;

if(strpos($event2_text,"|",0)) {$event2_text = substr($event2_text,0, strpos($event2_text,"|",0));}

// *** $text.='<a href="'.$url.'">'.$picqryDb->event_text.'</a></div><br>';

$text.='<a href="'.$url.'">'.$event2_text.'</a></div><br>';

// *** Show first available picture without privacy restrictions ***
break;
}

// *** TEST privacy filter ***
//else{
// $picname = str_replace(" ","_",$picqryDb->event_event);
// $text.='<img src="'.$tree_pict_path.$picname.'" width="200 px"
// style="border-radius: 15px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);">';
// $text.=$picqryDb->event_id.' tree_id:'.$picqryDb->event_tree_id.' ';
// $text.=$man_cls->privacy.'PRIVACY<br>';
//}
}
}

return $text;
}


In the file include/show_picture.php
at around line 215

change:
if ($source) $picture_text.=$source;

$process_text.='<div class="photo">';
$process_text.=$picture;
if (isset($picture_array['picture']) AND $picture_array['picture']=='missing-image.jpg') $picture_text.='<br><b>'.__('Missing image').':<br>'.$tree_pict_path.$event_event.'</b>';
if(strpos($picture_text,"|",0)) {$picture_text = substr($picture_text,0, strpos($picture_text,"|",0));}
// text for main page - title of picture

if(isset($picture_text)) {$process_text.='<div class="phototext">'.$picture_text.'</div>';}

$process_text.= '</div>'."\n";
}



else{
// *** Show photo using the lightbox effect ***
$picture_array=show_picture($tree_pict_path,$event_event,'',120);
// *** lightbox can't handle brackets etc so encode it. ("urlencode" doesn't work since it changes spaces to +, so we use rawurlencode)
// *** But: reverse change of / character (if sub folders are used) ***
//$picture_array['picture'] = rawurlencode($picture_array['picture']);
$picture_array['picture'] = str_ireplace("%2F","/",rawurlencode($picture_array['picture']));
$line_pos = strpos($media_event_text[$i],"|");
//$title_txt=''; if($line_pos !== false) $title_txt = substr($media_event_text[$i],0,$line_pos);
// $title_txt=$media_event_text[$i]; if($line_pos !== false) $title_txt = substr($media_event_text[$i],0,$line_pos);
$title_txt=$media_event_text[$i];
// *** Old Slimbox lightbox ***
//$picture='<a href="'.$picture_array['path'].$picture_array['picture'].'" rel="lightbox" title="'.str_replace("&", "&amp;", $title_txt).'">';

// *** April 2021: using GLightbox ***
//$picture='<a href="'.$picture_array['path'].$picture_array['picture'].'" data-glightbox="title: Title; description: '.str_replace("&", "&amp;", $title_txt).'" class="glightbox3" data-gallery="gallery'.$event_connect_id.'">';
//$picture='<a href="'.$picture_array['path'].$picture_array['picture'].'" data-glightbox="description: '.str_replace("&", "&amp;", $title_txt).'" class="glightbox3" data-gallery="gallery'.$event_connect_id.'">';

// Take 2nd part if exists as long description for popup

if(strpos($title_txt,"|",0)) {$title_txt = substr($title_txt, strpos($title_txt,"|",0)+1);}

// $picture='<a href="'.$picture_array['path'].$picture_array['picture'].'" class="glightbox3" data-gallery="gallery'.$event_connect_id.'" data-glightbox="description: .custom-desc'.$media_event_id[$i].'">';
$picture='<a href="'.$picture_array['path'].$picture_array['picture'].'" class="glightbox3" data-gallery="gallery'.$event_connect_id.'" data-glightbox="description: .custom-desc'.$media_event_id[$i].'">';
// *** Need a class for multiple lines and HTML code in a text ***

$picture.='<div class="glightbox-desc custom-desc'.$media_event_id[$i].'">'.$title_txt.'</div>';


$picture.='<img src="'.$picture_array['path'].$picture_array['thumb'].$picture_array['picture'].'" height="'.$picture_array['height'].'" alt="'.$event_event.'"></a>';

$templ_person["pic_path".$i]=$picture_array['path']."thumb_".$picture_array['picture']; //for the time being pdf only with thumbs
// *** Remove spaces ***
$templ_person["pic_path".$i]=trim($templ_person["pic_path".$i]);
}
Post Reply