i18n::translate('Random Media'),
'type'=>'both',
'descr'=>i18n::translate('The Random Media block randomly selects a photo or other media item from the currently active database and displays it to the user.
The administrator determines whether this block can show media items associated with persons or events.'),
'canconfig'=>true,
'config'=>array(
'cache' =>0,
'filter' =>'all',
'controls'=>'yes',
'start' =>'no',
'filter_avi' =>'no',
'filter_bmp' =>'yes',
'filter_gif' =>'yes',
'filter_jpeg' =>'yes',
'filter_mp3' =>'no',
'filter_ole' =>'yes',
'filter_pcx' =>'yes',
'filter_pdf' =>'no',
'filter_png' =>'yes',
'filter_tiff' =>'yes',
'filter_wav' =>'no',
'filter_audio' =>'no',
'filter_book' =>'yes',
'filter_card' =>'yes',
'filter_certificate'=>'yes',
'filter_coat' =>'yes',
'filter_document' =>'yes',
'filter_electronic' =>'yes',
'filter_fiche' =>'yes',
'filter_film' =>'yes',
'filter_magazine' =>'yes',
'filter_manuscript' =>'yes',
'filter_map' =>'yes',
'filter_newspaper' =>'yes',
'filter_other' =>'yes',
'filter_painting' =>'yes',
'filter_photo' =>'yes',
'filter_tombstone' =>'yes',
'filter_video' =>'no'
)
);
require_once WT_ROOT.'includes/functions/functions_print_facts.php';
//-- function to display a random picture from the gedcom
function print_random_media($block = true, $config="", $side, $index) {
global $foundlist, $MULTI_MEDIA, $TEXT_DIRECTION, $WT_IMAGE_DIR, $WT_IMAGES;
global $MEDIA_EXTERNAL, $MEDIA_DIRECTORY, $SHOW_SOURCES;
global $MEDIATYPE, $THUMBNAIL_WIDTH, $USE_MEDIA_VIEWER;
global $WT_BLOCKS, $ctype, $action;
global $WT_IMAGE_DIR, $WT_IMAGES;
if (!$MULTI_MEDIA) return;
if (empty($config)) $config = $WT_BLOCKS["print_random_media"]["config"];
if (isset($config["filter"])) $filter = $config["filter"]; // indi, event, or all
else $filter = "all";
if (!isset($config['controls'])) $config['controls'] ="yes";
if (!isset($config['start'])) $config['start'] ="no";
$medialist = array();
$foundlist = array();
$medialist = get_medialist(false, '', true, true);
$ct = count($medialist);
if ($ct>0) {
$i=0;
$disp = false;
//-- try up to 40 times to get a media to display
while($i<40) {
$error = false;
$value = array_rand($medialist);
if (WT_DEBUG) {
print "
";print_r($medialist[$value]);print "
";
print "Trying ".$medialist[$value]["XREF"]."
";
}
$links = $medialist[$value]["LINKS"];
$disp = ($medialist[$value]["EXISTS"]>0) && $medialist[$value]["LINKED"] && $medialist[$value]["CHANGE"]!="delete" ;
if (WT_DEBUG && !$disp && !$error) {$error = true; print "".$medialist[$value]["XREF"]." File does not exist, or is not linked to anyone, or is marked for deletion.
";}
$disp &= displayDetailsById($medialist[$value]["XREF"], "OBJE");
$disp &= !FactViewRestricted($medialist[$value]["XREF"], $medialist[$value]["GEDCOM"]);
if (WT_DEBUG && !$disp && !$error) {$error = true; print "".$medialist[$value]["XREF"]." Failed to pass privacy
";}
$isExternal = isFileExternal($medialist[$value]["FILE"]);
if ($block && !$isExternal) $disp &= ($medialist[$value]["THUMBEXISTS"]>0);
if (WT_DEBUG && !$disp && !$error) {$error = true; print "".$medialist[$value]["XREF"]." thumbnail file could not be found
";}
// Filter according to format and type (Default: unless configured otherwise, don't filter)
if (!empty($medialist[$value]["FORM"]) && isset($config["filter_".$medialist[$value]["FORM"]]) && $config["filter_".$medialist[$value]["FORM"]]!="yes") $disp = false;
if (!empty($medialist[$value]["TYPE"]) && isset($config["filter_".$medialist[$value]["TYPE"]]) && $config["filter_".$medialist[$value]["TYPE"]]!="yes") $disp = false;
if (WT_DEBUG && !$disp && !$error) {$error = true; print "".$medialist[$value]["XREF"]." failed Format or Type filters
";}
if ($disp && count($links) != 0){
/** link privacy allready checked in displayDetailsById
foreach($links as $key=>$type) {
$gedrec = find_gedcom_record($key, WT_GED_ID);
$disp &= !empty($gedrec);
//-- source privacy is now available through the display details by id method
// $disp &= $type!="SOUR";
$disp &= displayDetailsById($key, $type);
}
if (WT_DEBUG && !$disp && !$error) {$error = true; print "".$medialist[$value]["XREF"]." failed link privacy
";}
*/
if ($disp && $filter!="all") {
// Apply filter criteria
$ct = preg_match("/0\s(@.*@)\sOBJE/", $medialist[$value]["GEDCOM"], $match);
$objectID = $match[1];
//-- we could probably use the database for this filter
foreach($links as $key=>$type) {
$gedrec = find_gedcom_record($key, WT_GED_ID);
$ct2 = preg_match("/(\d)\sOBJE\s{$objectID}/", $gedrec, $match2);
if ($ct2>0) {
$objectRefLevel = $match2[1];
if ($filter=="indi" && $objectRefLevel!="1") $disp = false;
if ($filter=="event" && $objectRefLevel=="1") $disp = false;
if (WT_DEBUG && !$disp && !$error) {$error = true; print "".$medialist[$value]["XREF"]." failed to pass config filter
";}
}
else $disp = false;
}
}
}
//-- leave the loop if we find an image that works
if ($disp) {
break;
}
//-- otherwise remove the private media item from the list
else {
if (WT_DEBUG) print "".$medialist[$value]["XREF"]." Will not be shown
";
unset($medialist[$value]);
}
//-- if there are no more media items, then try to get some more
if (count($medialist)==0) $medialist = get_medialist(false, '', true, true);
$i++;
}
if (!$disp) return false;
$content = "";
$id = "";
$id = "random_picture$index";
$title='';
if ($WT_BLOCKS["print_random_media"]["canconfig"]) {
if ($ctype=="gedcom" && WT_USER_GEDCOM_ADMIN || $ctype=="user" && WT_USER_ID) {
if ($ctype=="gedcom") {
$name = WT_GEDCOM;
} else {
$name = WT_USER_NAME;
}
$title .= "";
$title .= "";
}
}
$title .= i18n::translate('Random Picture');
$title .= help_link('index_media');
$content = "
|
";
// $content .= " >";
// $content .= ">" . "\n";
$content .= " >";
}else
// ---------------------------------------------------------------------------------------------
if ($USE_MEDIA_VIEWER) {
$content .= " >";
}
else {
$content .= " >";
}
$mediaTitle = "";
if (!empty($medialist[$value]["TITL"])) {
$mediaTitle = PrintReady($medialist[$value]["TITL"]);
}
else $mediaTitle = basename($medialist[$value]["FILE"]);
if ($block) {
$content .= " "; else $content .= " | ";
$content .= "";
$content .= "". $mediaTitle ."";
$content .= " "; ob_start(); PrintMediaLinks($medialist[$value]["LINKS"], "normal"); $content .= ob_get_clean(); $content .= " ";
$content .= print_fact_notes($medialist[$value]["GEDCOM"], "1", false, true);
$content .= " ";
$content .= " |
| /> avi | /> bmp | /> gif | |
| /> jpeg | /> mp3 | /> ole | |
| /> pcx | /> png | ||
| /> tiff | /> wav |
| ".$typeValue." | "; } ?>