View source
<?php
if (module_exists('views')) {
require drupal_get_path('module', 'brilliant_gallery') . '/views.inc';
}
drupal_add_js(drupal_get_path('module', 'brilliant_gallery') . '/bgchecklist.js');
function brilliant_gallery_help($section = '') {
$output = '';
switch ($section) {
case "admin/help#brilliant_gallery":
$output = '<p>' . t("Highly customizable Drupal module creating a table gallery of quality-scaled images from any number of folders.") . '</p>';
break;
}
return $output;
}
function brilliant_gallery_perm() {
return array(
'access brilliant_gallery',
);
}
function brilliant_gallery_block($op = 'list', $delta = 0) {
if ($op == "list") {
$block[0]["info"] = t("Brilliant gallery");
return $block;
}
else {
if ($op == 'view') {
$block_content = '';
$block_content .= render_brilliant_gallery();
$block['subject'] = 'Brilliant gallery';
$block['content'] = $block_content;
return $block;
}
}
}
function brilliant_gallery_all($switch = '') {
$page_content = '';
if ($switch == '') {
$page_content .= render_brilliant_gallery();
}
else {
if ($switch == 'edit') {
$page_content .= render_brilliant_gallery_edit();
}
}
return $page_content;
}
function brilliant_gallery_checklist_loadall($nid = '') {
global $user;
$GLOBALS['devel_shutdown'] = FALSE;
$uid = $user->uid;
$dcvals = array();
$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}' ");
$count = 0;
while ($data = db_fetch_object($result)) {
$dcvals[$count] = array(
qid => $data->qid,
state => $data->state,
);
$count++;
}
print drupal_to_js($dcvals);
exit;
}
function brilliant_gallery_checklist_save($nid, $qid, $state) {
global $user;
$GLOBALS['devel_shutdown'] = FALSE;
if (preg_match("/^user-/", $qid) == 1) {
$uid = $user->uid;
}
else {
$uid = 0;
}
$existing = db_result(db_query("select count(state) from brilliant_gallery_checklist " . "where nid='{$nid}' and user='{$uid}' and qid='{$qid}'"));
if ($existing == 0) {
db_query("insert into brilliant_gallery_checklist (nid,user,qid,state) " . "values ('{$nid}','{$uid}','{$qid}','{$state}')");
}
elseif ($current != $state) {
$current = db_result(db_query("select state from brilliant_gallery_checklist " . " where nid='{$nid}' and user='{$uid}' and qid='{$qid}'"));
if ($current != $state) {
db_query("update brilliant_gallery_checklist " . "set state='{$state}' where nid='{$nid}' and user='{$uid}' and qid='{$qid}'");
}
}
print drupal_to_js("1");
exit;
}
function brilliant_gallery_checklist_docheckbox($matches) {
global $brilliant_gallery_checklist_matchcount;
$brilliant_gallery_checklist_matchcount++;
$output = <<<OUTPUT
<div class="bgchecklist"> <div class="form-item"> <input name="{<span class="php-variable">$matches</span>[<span class="php-constant">1</span>]}" id="{<span class="php-variable">$matches</span>[<span class="php-constant">1</span>]}" value="1" class="form-brilliant_gallery_checklist-checkbox" type="checkbox"> <label class="option"> {<span class="php-variable">$matches</span>[<span class="php-constant">2</span>]} </label> </div></div>
OUTPUT;
return $output;
}
function brilliant_gallery_admin() {
$form['brilliant_gallery_folder'] = array(
'#type' => 'textfield',
'#title' => t('Path to the main gallery folder'),
'#default_value' => variable_get('brilliant_gallery_folder', ''),
'#size' => 50,
'#maxlength' => 100,
'#description' => t("Path to the main folder in which your individual gallery folders will be placed. This folder must exist under your 'files' folder. Exclude trailing slashes. Example: <i>albums</i>"),
);
$form['brilliant_gallery_maxcol'] = array(
'#type' => 'textfield',
'#title' => t('Maximum number of table columns'),
'#default_value' => variable_get('brilliant_gallery_maxcol', 5),
'#size' => 2,
'#maxlength' => 2,
'#description' => t("The maximum number of columns displayed in the table."),
);
$form['brilliant_gallery_maximagewidth'] = array(
'#type' => 'textfield',
'#title' => t('Maximum width of table images'),
'#default_value' => variable_get('brilliant_gallery_maximagewidth', 150),
'#size' => 3,
'#maxlength' => 4,
'#description' => t("The maximum width of thumbnails in the table (height calculated automatically)."),
);
$form['brilliant_gallery_bcgcolour'] = array(
'#type' => 'colorpicker',
'#title' => t('Table background colour'),
'#default_value' => variable_get('brilliant_gallery_bcgcolour', '#000000'),
'#size' => 8,
'#maxlength' => 7,
'#description' => t("Pick colour of the background of the table that holds the images."),
);
$form['brilliant_gallery_bcgcolour_textfield'] = array(
'#type' => 'colorpicker_textfield',
'#title' => t('Current background color'),
'#description' => t(''),
'#default_value' => variable_get('brilliant_gallery_bcgcolour_textfield', '#000000'),
'#colorpicker' => 'brilliant_gallery_bcgcolour',
);
$form['brilliant_gallery_padding'] = array(
'#type' => 'textfield',
'#title' => t('Table cell padding'),
'#default_value' => variable_get('brilliant_gallery_padding', 3),
'#size' => 3,
'#maxlength' => 3,
'#description' => t("Cell padding (around each image) in pixels."),
);
$form['brilliant_gallery_overbrowser'] = array(
'#type' => 'select',
'#title' => t('Overlay browser'),
'#required' => FALSE,
'#options' => array(
'lightbox' => t('Lightbox'),
'thickbox' => t('Thickbox'),
'greyboxr' => t('Greybox Redux'),
'none' => t('None'),
),
'#default_value' => variable_get('brilliant_gallery_overbrowser', 'thickbox'),
'#description' => t('Select the overlay image browser (must be installed, of course).'),
);
$form['brilliant_gallery_maxwidth'] = array(
'#type' => 'textfield',
'#title' => t('Maximum width of full image'),
'#default_value' => variable_get('brilliant_gallery_maxwidth', '1000'),
'#size' => 5,
'#maxlength' => 5,
'#description' => t("Very large images will be scaled down to this width (in pixels) for display before they get displayed by the overlay browser."),
);
$form['brilliant_gallery_caption'] = array(
'#type' => 'checkbox',
'#title' => t('Display file name as caption'),
'#default_value' => variable_get('brilliant_gallery_caption', ''),
'#description' => t("Check this if you want the overlay browser to display a caption based on the image file name (dots and underscores are automatically replaced by spaces)."),
);
$form['brilliant_gallery_sort'] = array(
'#type' => 'radios',
'#title' => t('Sort or randomize image order'),
'#default_value' => variable_get('brilliant_gallery_sort', '1'),
'#options' => array(
'1' => t('Sort images by their file names alphabetically.'),
'' => t('The order of your gallery images will always be randomized (on each page load or cache refresh).'),
),
);
$form['brilliant_gallery_cache'] = array(
'#type' => 'radios',
'#title' => t('Database or file system caching of images'),
'#default_value' => variable_get('brilliant_gallery_cache', 'd'),
'#options' => array(
'd' => t('Use the <i>cache</i> table of Drupal.'),
'f' => t('Use the temporary directory you have set in <i>/admin/settings/file-system</i>. Faster than database caching!'),
),
'#description' => t("Only images (not the table as such) are cached so that they can be served quicker at subsequent requests."),
);
return system_settings_form($form);
}
function brilliant_gallery_perms() {
header("HTTP/1.1 301 Moved Permanently");
header("Location: /?q=admin/user/access#module-brilliant_gallery");
exit;
}
function brilliant_gallery_menu() {
$items = array();
$items[] = array(
'path' => 'admin/settings/brilliant_gallery',
'title' => t('Brilliant gallery'),
'description' => t('Brilliant gallery module settings'),
'callback' => 'drupal_get_form',
'callback arguments' => 'brilliant_gallery_admin',
'access' => user_access('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/settings/brilliant_gallery/permissions',
'title' => t('Configure permissions'),
'description' => t('Configure access permissions for the Brilliant gallery module'),
'callback' => 'brilliant_gallery_perms',
'access' => user_access('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/settings/brilliant_gallery/manage',
'title' => t('Manage galleries'),
'description' => t('Manage galleries displayed using the Brilliant gallery module - e.g. visibility of individual images, etc.'),
'callback' => 'render_brilliant_gallery_manage',
'access' => user_access('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'brilliant_gallery',
'title' => t('Brilliant gallery'),
'callback' => 'brilliant_gallery_all',
'access' => user_access('access brilliant_gallery'),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'bgchecklist/loadall',
'callback' => 'brilliant_gallery_checklist_loadall',
'type' => MENU_CALLBACK,
'access' => user_access('access brilliant_gallery'),
);
$items[] = array(
'path' => 'bgchecklist/save',
'callback' => 'brilliant_gallery_checklist_save',
'type' => MENU_CALLBACK,
'access' => user_access('access administration pages'),
);
return $items;
}
function render_brilliant_gallery_manage() {
$result = '';
$ac_header = <<<HEADER
<form action="" method="post" id="bgchecklist">
<div>
<div id="nodeid">
<input name="nid" id="edit-nid" value="9999999" type="hidden">
</div>
HEADER;
$result .= $ac_header;
$overbrowser = variable_get('brilliant_gallery_overbrowser', 'thickbox');
$setname = mt_rand(1, 9999999);
$galleryfolder = variable_get('brilliant_gallery_folder', '');
$path = url(file_directory_path() . '/' . $galleryfolder, NULL, NULL, TRUE);
if ($langcode != '') {
$path = str_replace('/' . $langcode . '/', '/', $path);
}
$path = str_replace("?q=", "", $path);
$absolpath = realpath(file_directory_path() . '/' . $galleryfolder);
$result .= '<p>';
$result .= '<p>This page allows you to set or unset visibility of each image (data item) in all Brilliant galleries there are on this website.';
ob_start();
$recurs = bg_iterative_recurse_dir($absolpath);
$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 .= '<p><b>Select an image folder:</b><ol>';
foreach ($dirshavefiles as $key => $val) {
$path_middle = str_replace($absolpath, '', $key);
$result .= '<li><a href="?fld=' . $galleryfolder . $path_middle . '">' . $galleryfolder . $path_middle . '</a></li>';
if ($galleryfolder . $path_middle == $_GET['fld']) {
$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);
$retval = array();
$cnt = 0;
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], '.')));
$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'];
$modulepath = url(drupal_get_path('module', 'brilliant_gallery'), NULL, NULL, TRUE);
if ($langcode != '') {
$modulepath = str_replace('/' . $langcode . '/', '/', $modulepath);
}
$modulepath = str_replace("?q=", "", $modulepath);
$displayimage = '';
if ($smallenough === true) {
$displayimage .= '<br><a href="' . $fullimgpath . '"';
}
else {
$displayimage .= '<a href="' . $modulepath . '/image.php?imgp=' . base64_encode($absolpath . $path_middle . '/' . $retval[$poct - 1]) . '&imgw=' . $imgwbig . '&imgh=' . $imghbig . '"';
}
switch ($overbrowser) {
case 'thickbox':
$displayimage .= ' class="thickbox"';
$displayimage .= ' rel="img_' . $setname . '"';
break;
case 'lightbox':
$displayimage .= ' rel="lightbox[' . $setname . ']"';
break;
case 'greyboxr':
$displayimage .= ' class="greybox"';
break;
default:
break;
}
if ($showcaption != '') {
if ($showcaption != 'filename') {
$caption = $showcaption;
}
$displayimage .= ' title="' . $caption . '"';
}
$displayimage .= '>';
$displayimage .= '<img style="border:0" alt="" src="' . $modulepath . '/image.php?imgp=' . base64_encode($absolpath . $path_middle . '/' . $retval[$poct - 1]) . '&imgw=' . $imgw . '&imgh=' . $imgh . '" />';
$displayimage .= '</a>';
}
else {
$displayimage .= '<a href="' . $fullimgpath . '">';
$displayimage .= $retval[$poct - 1];
$displayimage .= '</a>';
}
$tablerows[$cnt][0] = $displayimage;
$tablerows[$cnt][1] = '<font size="-1">' . $retval[$poct - 1] . '</font>';
$tmp = '';
$tmp .= '<div class="bgchecklist"> <div class="form-item"> <input name="' . 'user-' . md5($_GET['fld'] . '/' . $retval[$poct - 1]) . '" id="' . 'user-' . md5($_GET['fld'] . '/' . $retval[$poct - 1]) . '" value="1" class="form-brilliant_gallery_checklist-checkbox" type="checkbox"> <label class="option"> <font color=green>visible</font> </label> </div></div>';
$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 .= '<p>';
}
}
$result .= '</ol>';
$result .= "</div></form>";
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 = '') {
if (date('h') == '11' and date('i') == '11') {
cleantmpdir();
}
$langcode = '';
if (function_exists('i18n_get_lang')) {
$langcode = i18n_get_lang();
}
$result = '';
$galleryfolder = variable_get('brilliant_gallery_folder', '');
if (substr($galleryfolder, strlen($galleryfolder) - 1, 1) == '/' or substr($galleryfolder, 0, 1) == '/') {
return 'Main gallery folder path must not begin or end with a slash; please fix it in the <a href="/admin/settings/brilliant_gallery">settings page</a>.';
}
if ($thisfolder != '') {
$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') {
$showcaption = 'filename';
}
else {
if ($captionyesornot == 'no') {
$showcaption = '';
}
else {
$showcaption = $captionyesornot;
}
}
$padding = variable_get('brilliant_gallery_padding', 3);
$overbrowser = variable_get('brilliant_gallery_overbrowser', 'thickbox');
$fullresolutionmaxwidth = variable_get('brilliant_gallery_maxwidth', '1000');
$path = url(file_directory_path() . '/' . $galleryfolder, NULL, NULL, TRUE);
if ($langcode != '') {
$path = str_replace('/' . $langcode . '/', '/', $path);
}
$path = str_replace("?q=", "", $path);
$absolpath = realpath(file_directory_path() . '/' . $galleryfolder);
$temp = load_dir_to_array($absolpath, $imagewidth, $fullresolutionmaxwidth, $brilliant_gallery_sort);
$retval_dimensions = $temp[0];
$imagemaxh = $temp[1];
$maxpoct = count($retval_dimensions);
$excludedimgs = array();
$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;
}
$style_ul = "width: " . ($imagewidth + 2 * $padding) * $columns . "px;";
$column_count = 0;
$setname = mt_rand(1, 9999999);
$result .= '<!-- Brilliant Gallery Table Beginning -->';
$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 (array_search('user-' . md5($galleryfolder . '/' . $retval_dimensions[$poct - 1]['file']), $excludedimgs) !== 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 (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'];
$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;";
$result .= '<li style="' . $style_li . '">' . "\n";
$modulepath = url(drupal_get_path('module', 'brilliant_gallery'), NULL, NULL, TRUE);
if ($langcode != '') {
$modulepath = str_replace('/' . $langcode . '/', '/', $modulepath);
}
$modulepath = str_replace("?q=", "", $modulepath);
if ($smallenough === true) {
$result .= '<a href="' . $fullimgpath . '"';
}
else {
$result .= '<a href="' . $modulepath . '/image.php?imgp=' . base64_encode($absolpath . '/' . $retval[$poct - 1]) . '&imgw=' . $imgwbig . '&imgh=' . $imghbig . '"';
}
switch ($overbrowser) {
case 'thickbox':
$result .= ' class="thickbox"';
$result .= ' rel="img_' . $setname . '"';
break;
case 'lightbox':
$result .= ' rel="lightbox[' . $setname . ']"';
break;
case 'greyboxr':
$result .= ' class="greybox"';
break;
default:
break;
}
if ($showcaption != '') {
if ($showcaption != 'filename') {
$caption = $showcaption;
}
$result .= ' title="' . $caption . '"';
}
$result .= '>';
$result .= '<img style="border:0" alt="" src="' . $modulepath . '/image.php?imgp=' . base64_encode($absolpath . '/' . $retval[$poct - 1]) . '&imgw=' . $imgw . '&imgh=' . $imgh . '" />';
$result .= '</a>' . "\n";
}
else {
$result .= '<a href="' . $fullimgpath . '">';
$result .= $retval[$poct - 1];
$result .= '</a>' . "\n";
}
$result .= '</li>' . "\n";
$column_count += 1;
}
$result .= "</ul>\n";
$result .= '<br style="clear: both;" />';
return $result;
}
function load_dir_to_array($absolpath, $imagewidth, $fullresolutionmaxwidth, $brilliant_gallery_sort) {
$poct = -1;
$retval_dimensions = array();
$handle = opendir($absolpath);
$imagemaxh = 0;
while (@($file = readdir($handle))) {
$testending = strtolower(substr($file, -4, 4));
if (!testext($file) and strtolower($testending) != '.mpg' and strtolower($testending) != '.swf' and strtolower($testending) != '.mov') {
continue;
}
$poct += 1;
$retval_dimensions[$poct]['file'] = $file;
$temp = getimagesize($absolpath . '/' . $file);
if ($temp === false) {
continue;
}
if ($temp[0] - $temp[1] >= 0) {
$retval_dimensions[$poct]['imgw'] = $imagewidth;
$retval_dimensions[$poct]['imgh'] = round($temp[1] / $temp[0] * $imagewidth);
if ($temp[0] > $fullresolutionmaxwidth) {
$retval_dimensions[$poct]['imgwbig'] = $fullresolutionmaxwidth;
$retval_dimensions[$poct]['imghbig'] = round($temp[1] / $temp[0] * $fullresolutionmaxwidth);
}
else {
$retval_dimensions[$poct]['smallenough'] = true;
}
}
else {
$retval_dimensions[$poct]['imgw'] = round($temp[0] / $temp[1] * ($temp[0] / $temp[1]) * $imagewidth);
$retval_dimensions[$poct]['imgh'] = round($temp[0] / $temp[1] * $imagewidth);
if ($temp[0] > $fullresolutionmaxwidth) {
$retval_dimensions[$poct]['imgwbig'] = round($temp[0] / $temp[1] * ($temp[0] / $temp[1]) * $fullresolutionmaxwidth);
$retval_dimensions[$poct]['imghbig'] = round($temp[0] / $temp[1] * $fullresolutionmaxwidth);
}
else {
$retval_dimensions[$poct]['smallenough'] = true;
}
}
if ($imagemaxh < $retval_dimensions[$poct]['imgh']) {
$imagemaxh = $retval_dimensions[$poct]['imgh'];
}
}
@closedir($handle);
if ($brilliant_gallery_sort == '1') {
sort($retval_dimensions);
}
else {
shuffle($retval_dimensions);
}
return array(
$retval_dimensions,
$imagemaxh,
);
}
function brilliant_gallery_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'no cache':
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':
$text = replace_brilliant_gallery_tags($text);
return $text;
}
}
function replace_brilliant_gallery_tags($str) {
$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;
}
function cleantmpdir() {
$bgcachexpire = 3600 * 24 * 3;
$directory = file_directory_temp();
if (!($dirhandle = @opendir($directory))) {
return;
}
while (false !== ($filename = readdir($dirhandle))) {
if ($filename != "." && $filename != ".." && substr($filename, 0, 3) == 'bg_') {
$filename = $directory . "/" . $filename;
if (@filemtime($filename) < time() - $bgcachexpire) {
@unlink($filename);
}
}
}
}
function testext($filename) {
if (substr(strtolower($filename), -4, 4) == ".jpg" or substr(strtolower($filename), -5, 5) == ".jpeg" or substr(strtolower($filename), -4, 4) == ".gif" or substr(strtolower($filename), -4, 4) == ".png") {
return true;
}
return false;
}