HEADER;
$result .= $ac_header;
$overbrowser = variable_get('brilliant_gallery_overbrowser', 'lightbox');
$setname = mt_rand(1, 9999999);
$galleryfolder = variable_get('brilliant_gallery_folder', '');
$path = url(file_directory_path() .'/'. $galleryfolder, array('absolute' => TRUE));
# url() ads i18n codes to the URL ... we need to remove them here...
if ($langcode <> '') {
$path = str_replace('/'. $langcode .'/', '/', $path);
}
# Non-clean URLs need removing ?q=
$path = str_replace("?q=", "", $path);
$rp = file_directory_path();
if ($galleryfolder <> '') {
$rp .= '/'. $galleryfolder;
}
$absolpath = realpath($rp);
$result .= '
';
$result .= '
This page allows you to set or unset visibility of each image (data item) in all Brilliant galleries there are on this website.';
#$result .= '
Files folder: ' . file_directory_path() . '/';
ob_start();
$recurs = bg_iterative_recurse_dir($absolpath);
#echo '
'; print_r( $recurs ); echo ' ';
#echo '
'; print_r( $retval_dimensions ); echo ' ';
$result .= ob_get_contents();
$dirshavefiles = array();
foreach ($recurs as $key => $val) {
$temp = explode('/', $val);
$tempf = $temp[sizeof($temp) - 1];
unset($temp[sizeof($temp) - 1]);
$tempd = implode('/', $temp);
$dirshavefiles[$tempd][] = $tempf;
}
ksort($dirshavefiles);
$result .= '
Select an image folder:
';
foreach ($dirshavefiles as $key => $val) {
# Get just the folder name in the main gallery folder.
if ($galleryfolder == '' and $path_middle == '') {
$rootfolder = '/';
}
else {
$rootfolder = '';
}
$path_middle = str_replace($absolpath, '', $key);
$result .= ''. $galleryfolder . $path_middle . $rootfolder .' ';
if ($galleryfolder . $path_middle == $_GET['fld']) {
# User has asked to manage images in this folder.
$tablerows = array();
$temp = load_dir_to_array($key, variable_get('brilliant_gallery_maximagewidth', 150), variable_get('brilliant_gallery_maxwidth', '1000'), 1);
$retval_dimensions = $temp[0];
$imagemaxh = $temp[1];
$maxpoct = count($retval_dimensions);
#echo 'max: ' . $maxpoct;
#ob_start(); echo '
'; print_r( $retval_dimensions ); echo ' '; $result .= ob_get_contents();
# Thanks to Micha³ Albrecht!
$retval = array();
$cnt = 0;
#$path = url($key, array('absolute' => TRUE));
for ($poct = 1; $poct <= $maxpoct; $poct++) {
$cnt += 1;
$retval[$poct - 1] = $retval_dimensions[$poct - 1]['file'];
$fullimgpath = $path . $path_middle .'/'. $retval[$poct - 1];
if (testext($retval[$poct - 1])) {
$caption = str_replace(array('.', '_'), ' ', basename($retval[$poct - 1], strrchr($retval[$poct - 1], '.')));
#$smallenough = false;
$imgw = $retval_dimensions[$poct - 1]['imgw'];
$imgh = $retval_dimensions[$poct - 1]['imgh'];
$imgwbig = $retval_dimensions[$poct - 1]['imgwbig'];
$imghbig = $retval_dimensions[$poct - 1]['imghbig'];
#@$smallenough = $retval_dimensions[$poct - 1]['smallenough'];
#$style_li = "float: left; width: " . $imagewidth . "px; list-style: none; background: " . $bgcolour . "; height: " . $imagemaxh . "px; padding: " . $padding . "px; text-align: center; margin: 0; border: none;"; #$style_li = "float: left; list-style: none; background: #000; width: 44px; height: 33px; padding: 4px; text-align: center; margin: 0; border: none;";
#$result .= ('' . "\n");
# Get this module's path:
$modulepath = url(drupal_get_path('module', 'brilliant_gallery'), array('absolute' => TRUE));
# url() ads i18n codes to the URL ... we need to remove them here...
if ($langcode <> '') {
$modulepath = str_replace('/'. $langcode .'/', '/', $modulepath);
}
# Non-clean URLs need removing ?q=
$modulepath = str_replace("?q=", "", $modulepath);
$displayimage = '';
#if ($smallenough === true) {
# $displayimage .= 'nid? $node->nid: time()); // 'insert' has no $node->nid
break;
case 'lightbox':
$displayimage .= ' rel="lightbox['. $setname .']"';
#$attributes['rel'] = 'lightbox[' . ($node->nid? $node->nid: time()) . ']'; // 'insert' has no $node->nid
break;
case 'greybox':
$displayimage .= ' class="greybox"';
break;
default:
break;
}
if ($showcaption <> '') {
if ($showcaption <> 'filename') {
$caption = $showcaption;
}
$displayimage .= ' title="'. $caption .'"';
}
$displayimage .= '>';
# width="' . $imgw . '"
$displayimage .= ' ';
$displayimage .= ' ';
}
else {
$displayimage .= '';
#$result .= '' . $retval[$poct-1] . ' ';
$displayimage .= $retval[$poct - 1];
#brokenimage("Error loading PNG");
#$result .= ' ';
$displayimage .= '';
}
#$result .= ''. $retval[$poct-1] . ' '; # $fullimgpath
$tablerows[$cnt][0] = $displayimage;
$tablerows[$cnt][1] = ''. $retval[$poct - 1] .' ';
# We need some code for brilliant_gallery_checklist
$tmp = '';
# E.g. albums/2008/20080321-25_belgicko_zasypane_snehom/dsc02784_w1000.jpg
$tmp .= '';
$tablerows[$cnt][2] = $tmp;
}
$header = array('File name', 'Thumbnail', 'Gallery display');
$data = array();
foreach ($tablerows as $x => $val) {
$data[] = array('data' => array($tablerows[$x][0], $tablerows[$x][1], $tablerows[$x][2]));
}
$result .= theme_table($header, $data);
$result .= '';
}
}
$result .= '
';
# End of brilliant_gallery_checklist form.
$result .= "
";
return $result;
}
function bg_iterative_recurse_dir($from = '.') {
if (!is_dir($from)) {
return false;
}
$files = array();
$dirs = array($from);
while (NULL !== ($dir = array_pop($dirs))) {
if ($dh = opendir($dir)) {
while (false !== ($file = readdir($dh))) {
if ($file == '.' || $file == '..') {
continue;
}
$path = $dir .'/'. $file;
if (is_dir($path)) {
$dirs[] = $path;
}
else $files[] = $path;
}
closedir($dh);
}
}
return $files;
}
function render_brilliant_gallery($thisfolder = '', $colcountoverride = '', $widthoverride = '', $sortoverride = '', $maximumnumbertoshow = '', $colouroverride = '', $beginfromoverride = 1, $captionyesnotext = '') {
// Is this a Picasa gallery?
$picasafolder = false;
#echo '....'.substr($thisfolder,0,29);
if (substr($thisfolder,0,28) == 'http://picasaweb.google.com/') {
$picasafolder = true;
}
#drupal_add_css(drupal_get_path('module', 'brilliant_gallery') .'/brilliant_gallery.css');
# First some household cleaning. Delete expired cache files at 11:11 (if someone calls this script, of course!)
if (date('h') == '11' and date('i') == '11') {
#if ( date( 'h' ) == '12' ) {
#echo date( 'h' );
cleantmpdir();
}
# Patching a possible problem with i18n
$langcode = '';
if (function_exists('i18n_get_lang')) {
$langcode = i18n_get_lang();
}
#$result = '';
$result = '';
$galleryfolder = variable_get('brilliant_gallery_folder', '');
if (substr($galleryfolder, strlen($galleryfolder) - 1, 1) == '/' or substr($galleryfolder, 0, 1) == '/') {
#watchdog('error', 'failed to notify "weblogs.com" (site)');
#form_set_error('yemail', t('Header injection attempt detected. Do not enter line feed characters into the from field!'));
return 'Main gallery folder path must not begin or end with a slash; please fix it in the settings page .';
}
/*
if ($thisfolder <> '') {
$galleryfolder .= '/'. $thisfolder;
}
*/
if ( $thisfolder <> '') {
if ($galleryfolder <> '') {
$galleryfolder .= '/' . $thisfolder;
}
else{
$galleryfolder = $thisfolder;
}
}
if ($colcountoverride == '') {
$columns = variable_get('brilliant_gallery_maxcol', 3);
}
else {
$columns = $colcountoverride;
}
if ($widthoverride == '') {
$imagewidth = variable_get('brilliant_gallery_maximagewidth', 150);
}
else {
$imagewidth = $widthoverride;
}
if ($sortoverride == '' or strtolower($sortoverride) == 'sort') {
$brilliant_gallery_sort = variable_get('brilliant_gallery_sort', '1');
}
else {
$brilliant_gallery_sort = $sortoverride;
}
if ($colouroverride == '') {
$bgcolour = variable_get('brilliant_gallery_bcgcolour_textfield', '#000000');
}
else {
$bgcolour = $colouroverride;
}
#if ($captionyesornot == 'yes' or $captionyesornot == '' or (variable_get('brilliant_gallery_caption', '') <> '' and $captionyesornot <> 'no')) {
if (($captionyesnotext == 'yes' or $captionyesnotext == '') and variable_get('brilliant_gallery_caption', '') <> '' ) {
$showcaption = 'filename';
}
#else if ($captionyesornot == 'no') {
else if ($captionyesnotext == 'no' or (variable_get('brilliant_gallery_caption', '') == '' and ($captionyesnotext == 'yes' or $captionyesnotext == 'no'))) {
$showcaption = '';
}
else {
#$showcaption = $captionyesornot;
$showcaption = $captionyesnotext;
}
$padding = variable_get('brilliant_gallery_padding', 3);
$overbrowser = variable_get('brilliant_gallery_overbrowser', 'lightbox');
// Totally full resolution display would be impractical, so this is the maximum width of "full" resolution.
$fullresolutionmaxwidth = variable_get('brilliant_gallery_maxwidth', '1000');
$path = url(file_directory_path() .'/'. $galleryfolder, array('absolute' => TRUE));
// url() ads i18n codes to the URL ... we need to remove them here...
if ($langcode <> '') {
$path = str_replace('/'. $langcode .'/', '/', $path);
}
// Non-clean URLs need removing ?q=
$path = str_replace("?q=", "", $path);
// Get absolute path
if ($picasafolder) {
$url_to_fetch = $thisfolder;
#echo '.--..'.$url_to_fetch;
$mgalleryurl = md5($url_to_fetch);
$mkdirek = file_directory_temp() . '/bg_picasa_'. $mgalleryurl;
if (is_dir($mkdirek)===true) {
// If it exists, we assume it is also populated, so we don't create it, and we don't go fetching the remote data!
#echo 'exists';
}
else {
#echo 'new';
include ('./'. drupal_get_path('module', 'brilliant_gallery') ."/picasa.inc");
}
$absolpath = $mkdirek;
#$absolpath = '/tmp/bg_picasa_838e4e98afdffbec2ed6d34e6bfa497c';
#echo $absolpath;
#drupal_set_message(t('absol: '.$absolpath));
}
else {
$rp = file_directory_path();
if ($galleryfolder <> '') {
$rp .= '/'. $galleryfolder;
}
$absolpath = realpath($rp);
}
#$result .= $absolpath;
# Make an array with images in this folder, and their properties.
$temp = load_dir_to_array($absolpath, $imagewidth, $fullresolutionmaxwidth, $brilliant_gallery_sort);
$retval_dimensions = $temp[0];
$imagemaxh = $temp[1];
$maxpoct = count($retval_dimensions);
if (arg(2) == 'edit') {
#print_r( $retval_dimensions );
}
# Get a list of images that are forbidden from display.
#$uid=$user->uid;
#echo $user->uid;
$excludedimgs = array();
// any checkbox id that starts with user- we remember the current user's settings
// any other id is global and we use user=0
/*
$result=db_query("select qid,state from brilliant_gallery_checklist ".
" where nid='$nid' and qid not like 'user-%' and user=0 ".
" union ".
"select qid,state from brilliant_gallery_checklist ".
"where nid='$nid' and qid like 'user-%' and user='$uid' ");
*/
$dbresult = db_query("select qid from {brilliant_gallery_checklist} where qid like 'user-%' and state='1' ");
while ($data = db_fetch_object($dbresult)) {
$excludedimgs[] = $data->qid;
}
#print_r($excludedimgs);
# Total 'width' controls the number of thumbnails in each row. The number, in pixels, should be calculated thusly: [maximum width desired for thumbnails] + [padding - if any, x 2] + [margin - if any, x 2] + [border - if any, x 2] x [number of thumbnails desired in each row]
$style_ul = "font-size:0; margin:0px; padding:0px; width: ". (($imagewidth + 2 * $padding) * $columns) ."px;";
$column_count = 0;
#$pocetobr = 0;
$setname = mt_rand(1, 9999999);
#$result .= '';
$result .= '';
#if ( $thisfolder <> '' ) {
#$result .= ' align="center"';
# }
#$result .= ' style="width:' . $columns*$imagewidth . 'px;">'; #cell-spacing: 5px;
#$result .= ' style="width:' . $columns*$imagewidth . 'px;"';
#$result .= '>' . "\n"; #cell-spacing: 5px;
$maxpoct_show = '';
if ($maximumnumbertoshow <> '' and is_numeric($maximumnumbertoshow)) {
$maxpoct_show = $maximumnumbertoshow;
}
# Thanks to Micha³ Albrecht!
$retval = array();
$cnt = 0;
for ($poct = 1; $poct <= $maxpoct; $poct++) {
# Skip any images that were excluded from display.
# md5() must be made of the main gallery path etc. ending with the file name (unique identifier). E.g. albums/2008/20080321-25_belgicko_zasypane_snehom/dsc02784_w1000.jpg
if (array_search('user-'. md5($galleryfolder .'/'. $retval_dimensions[$poct - 1]['file']), $excludedimgs) !== false) {
continue;
}
if ($poct < $beginfromoverride) {
continue;
# Begin only from $beginfromoverride image.
}
$cnt += 1;
if ($cnt > $maxpoct_show and $maxpoct_show <> '') {
continue;
# Do not show more than $maxpoct_show (if defined).
}
$retval[$poct - 1] = $retval_dimensions[$poct - 1]['file'];
$fullimgpath = $path .'/'. $retval[$poct - 1];
#if ($column_count == 0) { $result .= (''); }
#$result .= ('');
#$result .= (' ' . "\n");
#$pocetobr += 1;
if (testext($retval[$poct - 1])) {
$caption = str_replace(array('.', '_'), ' ', basename($retval[$poct - 1], strrchr($retval[$poct - 1], '.')));
#$smallenough = false;
$imgw = $retval_dimensions[$poct - 1]['imgw'];
$imgh = $retval_dimensions[$poct - 1]['imgh'];
$imgwbig = $retval_dimensions[$poct - 1]['imgwbig'];
$imghbig = $retval_dimensions[$poct - 1]['imghbig'];
#@$smallenough = $retval_dimensions[$poct - 1]['smallenough'];
#$style_li = "float: left; list-style: none; background: #000; width: 44px; height: 33px; padding: 4px; text-align: center; margin: 0; border: none;";
$style_li = "font-size:0; float: left; width: ". $imagewidth ."px; list-style: none; background: ". $bgcolour ."; height: ". $imagemaxh ."px; padding: ". $padding ."px; text-align: center; margin: 0px; border: none;";
$result .= ('' . "\n");
# Get this module's path:
$modulepath = url(drupal_get_path('module', 'brilliant_gallery'), array('absolute' => TRUE));
# url() ads i18n codes to the URL ... we need to remove them here...
if ($langcode <> '') {
$modulepath = str_replace('/'. $langcode .'/', '/', $modulepath);
}
# Non-clean URLs need removing ?q=
$modulepath = str_replace("?q=", "", $modulepath);
#if ($smallenough === true) {
# $result .= 'nid? $node->nid: time()); // 'insert' has no $node->nid
break;
case 'lightbox':
$result .= ' rel="lightbox['. $setname .']"';
#$attributes['rel'] = 'lightbox[' . ($node->nid? $node->nid: time()) . ']'; // 'insert' has no $node->nid
break;
case 'greybox':
$result .= ' class="greybox"';
break;
default:
break;
}
if ($showcaption <> '') {
if ($showcaption <> 'filename') {
$caption = $showcaption;
}
$result .= ' title="'. $caption .'"';
}
$result .= '>';
# Important to begin with the "/" otherwise thumbnails in non-root folders fail. See http://drupal.org/node/175292
/*
$modulepath = url(drupal_get_path('module', 'brilliant_gallery'), array('absolute' => TRUE));
# url() ads i18n codes to the URL ... we need to remove them here...
if ( $langcode <> '' ) {
$modulepath = str_replace( '/' . $langcode . '/', '/', $modulepath );
}
# Non-clean URLs need removing ?q=
$modulepath = str_replace( "?q=", "", $modulepath );
*/
#$result .= ' '; # width="' . $imgw . '"
#$result .= ' '; # width="' . $imgw . '"
# width="' . $imgw . '"
$result .= ' ';
#$result .= ' ';
$result .= '' . "\n";
}
else {
$fosiz = ceil($imagewidth/13);
$style_li = "font-size:". $fosiz ."px; float: left; width: ". $imagewidth ."px; list-style: none; background: ". $bgcolour ."; height: ". $imagemaxh ."px; padding: ". $padding ."px; text-align: center; margin: 0px; border: none;";
$result .= (' ' . "\n");
$result .= '';
#$result .= '' . $retval[$poct-1] . ' ';
$result .= $retval[$poct - 1];
#brokenimage("Error loading PNG");
#$result .= ' ';
$result .= '' . "\n";
}
#$result .= ' ';
$result .= '' . "\n";
$column_count += 1;
#if ($column_count == $columns) { $result .= (" \n"); $column_count = 0; }
}
#if ($column_count <> 0) { $result .= (""); }
#if ($column_count <> 0) { $result .= ("\n"); }
#$result .= "
\n";
$result .= "\n";
#$result .= ' ';
#$result .= '';
return $result;
}
# Implementation of hook_filter().
function brilliant_gallery_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'no cache':
# See http://drupal.org/node/194318#comment-640952
return true;
case 'list':
return array(0 => t('Brilliant Gallery Tag'));
case 'description':
return t('Substitutes a special Brilliant Gallery Tag with the actual gallery table.');
case 'prepare':
return $text;
case 'process':
# process it here........
$text = replace_brilliant_gallery_tags($text);
return $text;
}
}
function replace_brilliant_gallery_tags($str) {
# [bg|path/to/gallery_folder|colcountoverride|widthoverride|sortorrandomoverride|maximumnumbertoshow|colouroverride|beginfromoverride|caption-yes-no-text]
# no slashes around this path!
$matchlink = '';
$orig_match = '';
preg_match_all("/(\[)bg(\|).*(\])/", $str, $matches);
foreach ($matches[0] as $match) {
$orig_match[] = $match;
$match = substr($match, 1, (strlen($match) - 2));
$match = explode("|", $match);
$matchlink[] = render_brilliant_gallery($match[1], $match[2], $match[3], $match[4], $match[5], $match[6], $match[7], $match[8]);
}
$str = str_replace($orig_match, $matchlink, $str);
return $str;
}
/**
* Implementation of hook_filter_tips().
*
* This hook allows filters to provide help text to users during the content
* editing process. Short tips are provided on the content editing screen, while
* long tips are provided on a separate linked page. Short tips are optional,
* but long tips are highly recommended.
*/
/*
function brilliant_gallery_filter_tips($delta, $format, $long = FALSE) {
switch ($delta) {
case 0:
if ($long) {
return t('Every instance of "foo" in the input text will be replaced with "%replacement".', array('%replacement' => variable_get('filter_example_foo_'. $format, 'bar')));
}
break;
case 1:
if ($long) {
return t('Every instance of the special <time /> tag will be replaced with the current date and time in the user\'s specified time zone.');
}
else {
return t('Use <time /> to display the current date/time.');
}
break;
}
}
*/