View source
<?php
define('BRILLIANT_GALLERY_DEFAULT_CACHE_DIR', 'brilliant_gallery_temp');
define('FILE_DIRECTORY_PATH', variable_get('file_public_path', conf_path() . '/files'));
if (function_exists('i18n_get_lang')) {
define('BG_LANGCODE', i18n_get_lang());
}
else {
define('BG_LANGCODE', '');
}
if (module_exists('views')) {
module_load_include('inc', 'brilliant_gallery', 'views');
}
module_load_include('inc', 'brilliant_gallery', 'brilliant_gallery_menu');
module_load_include('inc', 'brilliant_gallery', 'brilliant_gallery_functions');
module_load_include('inc', 'brilliant_gallery', 'brilliant_gallery_manage');
module_load_include('inc', 'brilliant_gallery', 'brilliant_gallery_showtime');
module_load_include('inc', 'brilliant_gallery', 'brilliant_gallery_cron');
require_once 'brilliant_gallery_formatters.inc';
function brilliant_gallery_help($path, $arg) {
switch ($path) {
case "admin/help#brilliant_gallery":
return '<h3>' . t('About') . '</h3>' . '<p>' . t("Highly customizable Drupal module creating a table gallery of quality-scaled images from any number of folders.") . '</p>';
}
}
function brilliant_gallery_permission() {
return array(
'access brilliant_gallery' => array(
'title' => t('Access Brilliant Gallery'),
'description' => t('Allow access to Brilliant Gallery.'),
),
'administer brilliant_gallery' => array(
'title' => t('Administer Brilliant Gallery'),
'description' => t('Set roles that may access the settings of Brilliant Gallery.'),
),
);
}
function brilliant_gallery_block_info() {
$block = array();
$block[0]["info"] = t("Brilliant Gallery");
return $block;
}
function brilliant_gallery_block_view($delta) {
$block_content = '';
$block_content .= render_brilliant_gallery();
$block = array();
$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=:nid1 and qid not like 'user-%' and user=0 " . " union " . "select qid,state from {brilliant_gallery_checklist} where nid=:nid2 and qid like 'user-%' and user=:uid ", array(
':nid1' => $nid,
':nid2' => $nid,
':uid' => $uid,
));
$count = 0;
foreach ($result as $data) {
$dcvals[$count] = array(
'qid' => $data->qid,
'state' => $data->state,
);
$count++;
}
print drupal_json_encode($dcvals);
exit;
}
function brilliant_gallery_checklist_save($nid = '', $qid = '', $state = '', $token = '') {
global $user;
$GLOBALS['devel_shutdown'] = FALSE;
if (drupal_valid_token($token, 'render_brilliant_gallery_manage')) {
}
else {
watchdog('Brilliant Gal', 'Invalid token submitted from bgchecklist/save', NULL, WATCHDOG_ALERT);
return;
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
}
else {
watchdog('Brilliant Gal', 'Not an AJAX request from bgchecklist/save', NULL, WATCHDOG_ALERT);
return;
}
if ($nid == 9999999 && $qid != '' && ($state == 0 || $state == 1)) {
$qid = check_plain($qid);
}
else {
watchdog('Brilliant Gal', 'Invalid request from bgchecklist/save', NULL, WATCHDOG_ALERT);
return;
}
if (preg_match("/^user-/", $qid) == 1) {
$uid = $user->uid;
}
else {
$uid = 0;
}
$existing = db_query("select count(state) from {brilliant_gallery_checklist} " . "where nid=:nid and user=:uid and qid=:qid", array(
':nid' => $nid,
':uid' => $uid,
':qid' => $qid,
))
->fetchField();
if ($existing == 0) {
db_query("insert into {brilliant_gallery_checklist} (nid,user,qid,state) " . "values (:nid,:uid,:qid,:state)", array(
':nid' => $nid,
':uid' => $uid,
':qid' => $qid,
':state' => $state,
));
}
else {
$current = db_query("select state from {brilliant_gallery_checklist} " . " where nid=:nid and user=:uid and qid=:qid", array(
':nid' => $nid,
':uid' => $uid,
':qid' => $qid,
))
->fetchField();
if ($current != $state) {
db_query("update {brilliant_gallery_checklist} " . "set state=:state where nid=:nid and user=:uid and qid=:qid", array(
':state' => $state,
':nid' => $nid,
':uid' => $uid,
':qid' => $qid,
));
}
}
print drupal_json_encode("1");
exit;
}
function brilliant_gallery_checklist_docheckbox($matches) {
global $brilliant_gallery_checklist_matchcount;
$brilliant_gallery_checklist_matchcount++;
$name = check_plain($matches[1]);
$label = filter_xss($matches[2]);
$output = <<<OUTPUT
<div class="bgchecklist"> <div class="form-item"> <input name="{<span class="php-variable">$name</span>}" id="{<span class="php-variable">$name</span>}" value="1" class="form-brilliant_gallery_checklist-checkbox" type="checkbox"> <label class="option"> {<span class="php-variable">$label</span>} </label> </div></div>
OUTPUT;
return $output;
}
function brilliant_gallery_admin($form, &$form_state) {
$form['brilliant_gallery_folder'] = array(
'#type' => 'textfield',
'#title' => t('Main gallery folder used for local galleries (not for Picasa)'),
'#default_value' => variable_get('brilliant_gallery_folder', ''),
'#size' => 77,
'#maxlength' => 333,
'#description' => t("Enter the name of the main folder in which you plan to store all your future gallery folders.\n This base folder must be located under your default file system folder (see your file system path in /admin/settings/file-system/settings).\n If this main folder does not exist under the file system folder, create it first. Do not use trailing slashes.\n Enter, for example, <i>albums</i> or <i>myimages/albums</i>. If you leave this field empty your gallery will show only images that reside\n directly in the root of your file system folder."),
);
$form['brilliant_gallery_pcache'] = array(
'#type' => 'textfield',
'#title' => t('Custom path for a cache folder'),
'#default_value' => variable_get('brilliant_gallery_pcache', BRILLIANT_GALLERY_DEFAULT_CACHE_DIR),
'#size' => 77,
'#maxlength' => 333,
'#description' => t("Temporary storage (cache) for resized local images and for images fetched from Picasa.\n <br />It is OK to leave this field empty. If such case, a directory called 'brilliant_gallery_temp' will automatically be created in your /files directory.\n (FYI: your /files directory is defined at /admin/settings/file-system)\n <br />Otherwise, you can set here a custom path to a caching directory within your /files directory. Exclude trailing slashes. Example: <i>my_brilliant_gallery_temp</i>.\n If this directory does not exist, the module will attempt to create it automatically. Note that only single directories (e.g. <i>my_brilliant_gallery_temp</i>)\n can be created automatically. Paths such as e.g. <i>allmycaches/my_brilliant_gallery_temp</i> are valid as well but you have to create them manually."),
);
$form['brilliant_gallery_cache_duration'] = array(
'#type' => 'textfield',
'#title' => t('Expiration time of the gallery cache (in days)'),
'#default_value' => variable_get('brilliant_gallery_cache_duration', '90'),
'#size' => 5,
'#maxlength' => 5,
'#description' => t("Images and other gallery structures are cached to improve speed of serving. Here you can set how long time they should be cached."),
);
$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. If this is zero, the images will fill the row and continue on a next one."),
);
$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_crop'] = array(
'#type' => 'select',
'#title' => t('Crop thumbnails to square shape'),
'#required' => FALSE,
'#options' => array(
'yes' => t('yes'),
'no' => t('no'),
),
'#default_value' => variable_get('brilliant_gallery_crop', 'no'),
'#description' => t("If selected, all image thumbnails will have the same square shape."),
);
$color_field_type = (function_exists('colorpicker_2_or_later') ? 'colorpicker_' : '') . 'textfield';
$form['brilliant_gallery_bcgcolour_textfield'] = array(
'#type' => $color_field_type,
'#title' => t('Background colour'),
'#description' => t('Please enter a color value in the form #RRGGBB'),
'#default_value' => variable_get('brilliant_gallery_bcgcolour_textfield', '#000000'),
);
$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(
'colorbox' => t('Colorbox'),
'lightbox' => t('Lightbox'),
'none' => t('None'),
),
'#default_value' => variable_get('brilliant_gallery_overbrowser', 'colorbox'),
'#description' => t('Select the overlay image browser (the relevant module 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', '1920'),
'#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).'),
),
);
return system_settings_form($form);
}
function brilliant_gallery_admin_validate($form, &$form_state) {
$brilliant_gallery_folder = $form_state['values']['brilliant_gallery_folder'];
if (substr($brilliant_gallery_folder, 0, 1) == "/" or substr($brilliant_gallery_folder, -1, 1) == "/") {
form_set_error('brilliant_gallery_folder', 'The path should not start or end with a slash.');
}
$dir = realpath(FILE_DIRECTORY_PATH) . '/' . $brilliant_gallery_folder;
if (!file_exists($dir) or !is_dir($dir)) {
if (!mkdir($dir)) {
form_set_error('brilliant_gallery_folder', 'Directory ' . $brilliant_gallery_folder . ' does not exist in ' . FILE_DIRECTORY_PATH . '/ and it was not possible to create it automatically.');
}
}
$brilliant_gallery_pcache = $form_state['values']['brilliant_gallery_pcache'];
if (trim($brilliant_gallery_pcache) == '') {
$brilliant_gallery_pcache = BRILLIANT_GALLERY_DEFAULT_CACHE_DIR;
}
if (substr($brilliant_gallery_pcache, 0, 1) == "/" or substr($brilliant_gallery_pcache, -1, 1) == "/") {
form_set_error('brilliant_gallery_pcache', 'The path should not start or end with a slash.');
}
else {
$path = FILE_DIRECTORY_PATH . "/" . $brilliant_gallery_pcache;
if (file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {
$form_state['values']['brilliant_gallery_pcache'] = $brilliant_gallery_pcache;
}
else {
form_set_error('brilliant_gallery_pcache', "Directory " . $brilliant_gallery_pcache . " in your /files folder either could not be created or is not writable.");
}
}
}
function brilliant_gallery_perms() {
drupal_goto('admin/people/permissions', array(
'fragment' => 'module-brilliant_gallery',
));
}
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 brilliant_gallery_filter_info() {
$filters = array();
$filters['filter_brilliant_gallery'] = array(
'title' => t('Brilliant Gallery tag'),
'description' => t('Substitutes a special Brilliant Gallery tag [bg|...] with the actual gallery table.'),
'prepare callback' => 'brilliant_gallery_filter_brilliant_gallery_prepare',
'process callback' => 'brilliant_gallery_filter_brilliant_gallery_process',
);
return $filters;
}
function brilliant_gallery_filter_brilliant_gallery_prepare($text, $filter) {
return $text;
}
function brilliant_gallery_filter_brilliant_gallery_process($text, $filter) {
$text = replace_brilliant_gallery_tags($text);
return $text;
}
function brilliant_gallery_filter_XXX($op, $delta = 0, $format = -1, $text = '') {
}
function brilliant_gallery_get_allowed_params() {
$allowed_params = array(
1 => 'location',
2 => 'thumbcolumns',
3 => 'thumbwidth',
4 => 'thumbsort',
5 => 'thumbmaxshow',
6 => 'thumbbackcolour',
7 => 'thumbstartfrom',
8 => 'fullcaption',
9 => 'fullwidth',
10 => 'thumbsquared',
11 => 'thumbpadding',
12 => 'thumbslideshow',
13 => 'thumbshowbyname',
14 => 'thumbhtmlcache',
15 => 'thumbalignincell',
);
return $allowed_params;
}