View source
<?php
function render_brilliant_gallery($paramarray = array()) {
$thisfolder = '';
if (isset($paramarray[1])) {
$thisfolder = $paramarray[1];
}
$colcountoverride = @$paramarray[2];
$widthoverride = @$paramarray[3];
$sortoverride = @$paramarray[4];
$maximumnumbertoshow = @$paramarray[5];
$colouroverride = @$paramarray[6];
$beginfromoverride = @$paramarray[7];
if ($beginfromoverride == '') {
$beginfromoverride = 1;
}
$captionyesnotext = @$paramarray[8];
@($paramarray[10] = strtolower(@$paramarray[10]));
if ($paramarray[10] == 'yes' or $paramarray[10] == 'no') {
$imagecrop = $paramarray[10];
}
else {
$imagecrop = variable_get('brilliant_gallery_crop', 'no');
}
if (@$paramarray[12] == '') {
$paramarray[12] = 'no';
}
$bgcachexpire = brilliant_gallery_get_days_in_seconds(variable_get('brilliant_gallery_cache_duration', 90));
$thumbalignincell = strtolower(@$paramarray[15]);
if ($thumbalignincell != 'center' and $thumbalignincell != 'left' and $thumbalignincell != 'right') {
$thumbalignincell = 'center';
}
$picasawebsignature = 'http://plus.google.com/';
$picasawebsignaturesecure = 'https://plus.google.com/';
if (substr($thisfolder, 0, strlen($picasawebsignature)) == $picasawebsignature or substr($thisfolder, 0, strlen($picasawebsignaturesecure)) == $picasawebsignaturesecure) {
$urlquery = parse_url($thisfolder, PHP_URL_QUERY);
parse_str($urlquery, $parsedquery);
$authkey = '';
if (@$parsedquery['authkey'] != '') {
$authkey = 'Gv1sRg' . $parsedquery['authkey'];
}
$urlpath = parse_url($thisfolder, PHP_URL_PATH);
$urlpath = explode('/', $urlpath);
$picasauserid = '';
$picasaalbumid = '';
foreach ($urlpath as $key => $val) {
if (is_numeric($val) and strlen($val) > 10 and $picasauserid == '') {
$picasauserid = $val;
}
else {
if (is_numeric($val) and strlen($val) > 10 and $picasauserid != '') {
$picasaalbumid = $val;
}
}
}
$thisfolder = 'https://picasaweb.google.com/data/feed/base/user/' . $picasauserid . '/albumid/' . $picasaalbumid . '?alt=rss&kind=photo';
if ($authkey != '') {
$thisfolder .= '&authkey=' . $authkey;
}
}
$picasafolder = false;
$picasawebsignature = 'http://picasaweb.google.';
$picasawebsignaturesecure = 'https://picasaweb.google.';
if (substr($thisfolder, 0, strlen($picasawebsignature)) == $picasawebsignature or substr($thisfolder, 0, strlen($picasawebsignaturesecure)) == $picasawebsignaturesecure) {
$thisfolder = str_replace("&", "&", $thisfolder);
$picasafolder = true;
}
$thumbshowbyname = array();
$tmp = explode(',', @$paramarray[13]);
if (is_array($tmp)) {
foreach ($tmp as $val) {
$val = trim($val);
if ($val == '') {
continue;
}
$thumbshowbyname[] = $val;
}
}
$result = '';
$galleryfolder = variable_get('brilliant_gallery_folder', '');
if ($thisfolder != '') {
if ($galleryfolder != '') {
$galleryfolder .= (substr($thisfolder, 0, 1) == '/' ? '' : '/') . $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 = check_plain(variable_get('brilliant_gallery_bcgcolour_textfield', '#000000'));
}
else {
$bgcolour = $colouroverride;
}
if (($captionyesnotext == 'yes' or $captionyesnotext == '') and variable_get('brilliant_gallery_caption', '') != '') {
$showcaption = 'filename';
}
else {
if ($captionyesnotext == 'no' or variable_get('brilliant_gallery_caption', '') == '' and ($captionyesnotext == 'yes' or $captionyesnotext == 'no')) {
$showcaption = '';
}
else {
$showcaption = $captionyesnotext;
}
}
$padding = check_plain(variable_get('brilliant_gallery_padding', 3));
$overbrowser = variable_get('brilliant_gallery_overbrowser', 'colorbox');
$fullresolutionmaxwidth = variable_get('brilliant_gallery_maxwidth', '1000');
$path = url(FILE_DIRECTORY_PATH . '/' . $galleryfolder, array(
'absolute' => TRUE,
));
if (BG_LANGCODE != '') {
$path = str_replace('/' . BG_LANGCODE . '/', '/', $path);
}
$path = str_replace("?q=", "", $path);
if ($paramarray[12] == 'yes' and $picasafolder) {
$slideshowurl = str_replace('/base/', '/api/', $thisfolder);
$result .= '<embed type="application/x-shockwave-flash" src="https://picasaweb.google.com/s/c/bin/slideshow.swf" width="' . $widthoverride . '" height="' . $widthoverride * 0.75 . '" flashvars="host=picasaweb.google.com&hl=en_US&feat=flashalbum&interval=20&RGB=0x000000&feed=' . urlencode($slideshowurl) . '" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
}
else {
if ($picasafolder) {
$url_to_fetch = $thisfolder;
$mgalleryurl = md5($url_to_fetch);
$pcachetemp = variable_get('brilliant_gallery_pcache', BRILLIANT_GALLERY_DEFAULT_CACHE_DIR);
if ($pcachetemp == '' or $pcachetemp == file_directory_temp()) {
$pcachetemp = file_directory_temp();
$beg_realpcachetemp = file_directory_temp();
$slashpcachetemp = '';
}
else {
$slashpcachetemp = '/' . $pcachetemp;
$beg_realpcachetemp = realpath(FILE_DIRECTORY_PATH) . $slashpcachetemp;
}
$mkdirek = $beg_realpcachetemp . '/bg_picasa_orig_' . $mgalleryurl;
if ($url_to_fetch == '') {
return;
}
@mkdir($mkdirek);
$url_to_fetch = str_replace('https://', 'http://', $url_to_fetch);
$cacheid_url_to_fetch = 'bg_gallery_picasa_xml_' . md5($url_to_fetch);
if ($cache = cache_get($cacheid_url_to_fetch) and !empty($cache->data)) {
$html = $cache->data;
}
else {
$timenow = REQUEST_TIME;
$htmlobj = drupal_http_request($url_to_fetch);
$html = $htmlobj->data;
cache_set($cacheid_url_to_fetch, $html, 'cache', brilliant_gallery_get_time_this_many_seconds_from_now($bgcachexpire));
watchdog('Brilliant Gal', 'Fetched XML from ' . $url_to_fetch . ' (' . strlen($html) . ' bytes). Elapsed time: ' . (REQUEST_TIME - $timenow) . ' seconds.');
}
$imgchunks = explode("' url='", $html);
$fetchingnow = 0;
$timenow = REQUEST_TIME;
foreach ($imgchunks as $imgchunk) {
drupal_set_time_limit(360);
$chunk2 = explode("' length='", $imgchunk);
$imgurl = trim($chunk2[0]);
if (substr($imgurl, 0, 4) != 'http') {
continue;
}
$imagename = substr($imgurl, strrpos($imgurl, '/') + 1);
$foqen = $mkdirek . '/' . $imagename;
$lastchanged = @filemtime($foqen);
if ($lastchanged === FALSE or $timenow - $lastchanged > $bgcachexpire) {
@unlink($foqen);
$imager = drupal_http_request($imgurl);
$image = $imager->data;
if (strlen($image) > 0) {
$fp = fopen($foqen, 'w');
watchdog('bg', $foqen . ' ...ok<br>');
fwrite($fp, $image);
fclose($fp);
$fetchingnow++;
}
}
}
if ($fetchingnow != 0) {
watchdog('Brilliant Gal', 'Fetched ' . $fetchingnow . ' images from ' . $url_to_fetch . '. Elapsed time: ' . (REQUEST_TIME - $timenow) . ' seconds.');
}
$absolpath = $slashpcachetemp . '/bg_picasa_orig_' . $mgalleryurl;
}
else {
$absolpath = '/' . $galleryfolder;
}
$temp = load_dir_to_array($absolpath, $imagewidth, $fullresolutionmaxwidth, $brilliant_gallery_sort, $imagecrop, $maximumnumbertoshow);
$retval_dimensions = $temp[0];
$imagemaxh = $temp[1];
$maxpoct = count($retval_dimensions);
if (!$picasafolder) {
$excludedimgs = array();
$dbresult = db_query("select qid from {brilliant_gallery_checklist} where qid like 'user-%' and state='1' ");
foreach ($dbresult as $data) {
$excludedimgs[] = $data->qid;
}
}
if ($maximumnumbertoshow == 1) {
$columns = 0;
}
if ($columns != 0) {
$style_ul = "font-size: 0px; margin: 0px; padding: 0px; width: " . ($imagewidth + 2 * $padding) * $columns . "px;";
}
else {
$style_ul = "font-size: 0; margin: 0px; padding: 0px;";
}
$column_count = 0;
$setname = md5($absolpath);
$result .= '<ul style="' . $style_ul . '">';
$maxpoct_show = '';
if ($maximumnumbertoshow != '' and is_numeric($maximumnumbertoshow)) {
$maxpoct_show = $maximumnumbertoshow;
}
$retval = array();
$cnt = 0;
for ($poct = 1; $poct <= $maxpoct; $poct++) {
if (!$picasafolder) {
if (array_search('user-' . md5($galleryfolder . '/' . $retval_dimensions[$poct - 1]['file']), $excludedimgs) !== false) {
continue;
}
}
if (!empty($thumbshowbyname)) {
if (array_search($retval_dimensions[$poct - 1]['file'], $thumbshowbyname) === FALSE) {
continue;
}
}
if ($poct < $beginfromoverride) {
continue;
}
$cnt += 1;
if ($cnt > $maxpoct_show and $maxpoct_show != '') {
continue;
}
$retval[$poct - 1] = $retval_dimensions[$poct - 1]['file'];
$fullimgpath = $path . '/' . $retval[$poct - 1];
if (brilliant_gallery_testext($retval[$poct - 1])) {
$caption = str_replace(array(
'.',
'_',
), ' ', basename($retval[$poct - 1], strrchr($retval[$poct - 1], '.')));
$imgw = $retval_dimensions[$poct - 1]['imgw'];
$imgh = $retval_dimensions[$poct - 1]['imgh'];
$imgwbig = $retval_dimensions[$poct - 1]['imgwbig'];
$imghbig = $retval_dimensions[$poct - 1]['imghbig'];
$imgcrop = $retval_dimensions[$poct - 1]['imgcrop'];
$imagemaxh_here = $imagemaxh;
$imagewidth_here = $imagewidth;
if ($maximumnumbertoshow == 1) {
$imagemaxh_here = $imgh;
$imagewidth_here = $imgw;
}
$style_li = "font-size: 0px; float: left; width: " . $imagewidth_here . "px; list-style: none; background: " . $bgcolour . "; height: " . $imagemaxh_here . "px; padding: " . $padding . "px; text-align: " . $thumbalignincell . "; margin: 0px; border: none;";
$result .= '<li style="' . $style_li . '">' . "\n";
$modulepath = drupal_get_path('module', 'brilliant_gallery');
if (BG_LANGCODE != '') {
$modulepath = str_replace('/' . BG_LANGCODE . '/', '/', $modulepath);
}
$modulepath = str_replace("?q=", "", $modulepath);
$bgimgproperties_array = array(
'imgp' => $absolpath . '/' . $retval[$poct - 1],
'imgw' => $imgwbig,
'imgh' => $imghbig,
'imgcrop' => 'no',
);
$bgimgproperties_array_token = brilliant_gallery_image_properties_set($bgimgproperties_array);
$pcache = variable_get('brilliant_gallery_pcache', BRILLIANT_GALLERY_DEFAULT_CACHE_DIR);
$imgsrc = file_create_url(FILE_DIRECTORY_PATH . '/' . $pcache . '/bg_cached_resized_' . $bgimgproperties_array_token . '.' . brilliant_gallery_get_extension($retval[$poct - 1]));
$result .= '<a href="' . $imgsrc . '"';
switch ($overbrowser) {
case 'colorbox':
$result .= ' class="colorbox" rel="bg-' . $setname . '"';
break;
case 'lightbox':
$result .= ' rel="lightbox[' . $setname . ']"';
break;
default:
break;
}
if ($showcaption != '') {
if ($showcaption != 'filename') {
$caption = $showcaption;
}
$result .= ' title="' . $caption . '"';
}
$result .= '>';
$bgimgproperties_array = array(
'imgp' => $absolpath . '/' . $retval[$poct - 1],
'imgw' => $imgw,
'imgh' => $imgh,
'imgcrop' => $imgcrop,
);
$bgimgproperties_array_token = brilliant_gallery_image_properties_set($bgimgproperties_array);
$pcache = variable_get('brilliant_gallery_pcache', BRILLIANT_GALLERY_DEFAULT_CACHE_DIR);
$imgsrc = file_create_url(FILE_DIRECTORY_PATH . '/' . $pcache . '/bg_cached_resized_' . $bgimgproperties_array_token . '.' . brilliant_gallery_get_extension($retval[$poct - 1]));
$secur = empty($_SERVER["HTTPS"]) ? '' : $_SERVER["HTTPS"] == "on" ? "s" : "";
if ($secur == 's') {
$imgsrc = str_replace('http://', 'https://', $imgsrc);
}
$result .= '<img style="border: 0px; margin: 0px; padding: 0px;" alt="" src="' . $imgsrc . '" />';
$result .= '</a>' . "\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: " . $thumbalignincell . "; margin: 0px; border: none;";
$result .= '<li style="' . $style_li . '">' . "\n";
$result .= '<a href="' . $fullimgpath . '">';
$result .= $retval[$poct - 1];
$result .= '</a>' . "\n";
}
$result .= '</li>' . "\n";
$column_count += 1;
}
$result .= "</ul>\n";
$result .= "<div style=\"clear: both;\"></div>\n";
}
return $result;
}