gallery_assist.module in Gallery Assist 6
Same filename and directory in other branches
Drupal content type with gallery functionality.
5 DB tables belonging to this module.
- gallery_assist - Contain the gallery-information and configuration data.
- gallery_assist_items - Here will be stored the items data (currently are only images).
- gallery_assist_translated - Contains the title and the description of each item and the translations.
- cache_gallery_assist_data - Contains the needed content and settings data from Gallery Assist assignments.
- gallery_assist_modules_settings - Contains the settings data from modules which work together with Gallery Assist.
File
gallery_assist.moduleView source
<?php
// $Id: gallery_assist.module,v 1.1.2.83 2011/02/07 23:39:40 jcmc Exp $
/**
* @file
* Drupal content type with gallery functionality.
*
* 5 DB tables belonging to this module.
* - gallery_assist - Contain the gallery-information and configuration data.
* - gallery_assist_items - Here will be stored the items data (currently are only images).
* - gallery_assist_translated - Contains the title and the description of each item and the translations.
* - cache_gallery_assist_data - Contains the needed content and settings data from Gallery Assist assignments.
* - gallery_assist_modules_settings - Contains the settings data from modules which work together with Gallery Assist.
*/
/**
* Advertise the current GA api version
*/
function gallery_assist_api_version() {
return '1';
}
/**
* Information to other GA modules.
*/
function gallery_assist_api_minimum_version() {
return '1';
}
/**
* Implementation of hook_init().
*/
function gallery_assist_init() {
global $user, $language;
gallery_assist_add_css('gallery_assist');
// Create the user gallery_assist directory if the user has the right permission.
$gallery_assist_paths[] = variable_get('gallery_assist_directory', file_directory_path() . '/gallery_assist');
$gallery_assist_paths[] = $user->uid;
if (file_check_directory($gallery_assist_paths[0], 1)) {
$gallery_assist_user_upload_path = implode('/', $gallery_assist_paths);
if (!is_dir($gallery_assist_user_upload_path)) {
$types = node_get_types();
foreach ($types as $v) {
if (user_access('create gallery_assist content') || user_access('create gallery_assist_' . $v->type . ' content')) {
file_check_directory($gallery_assist_user_upload_path, 1);
}
}
}
}
}
/**
* Implementation of hook_help().
*/
function gallery_assist_help($path, $arg) {
// gallery_assist_add_css('gallery_assist');
$t = get_t();
switch ($path) {
case 'admin/help#gallery_assist':
$output = $t('<p>Install the <a href="@advhelp" target="_blank">Advanced Help</a> module to read the documantation of GA or visit the <a href="@prepage" target="_blank">presentation page</a>.</p>', array(
'@advhelp' => url('http://www.drupal.org/project/advanced_help'),
'@prepage' => url('http://simple.puntolatinoclub.de/docu/gallery-assist'),
));
return $output;
break;
}
}
/**
* Help for users with create gallery_assist permition.
*
* @return
* The help text as string.
*/
function gallery_assist_users_help() {
global $base_url;
drupal_set_title(t('Gallery Assist Help.'));
$output = gallery_assist_help_text();
return $output;
}
/**
* TODO: The help should be partitioned acord the different sections (paths).
* Print the help text for users and administrators.
*/
function gallery_assist_help_text() {
global $base_url;
$output = '';
return $output;
}
/**
* Provide more Advanced Help functionality for Galley Assist and submodules.
*
* @param $in An array with the needed data to build and display a advanced help link.
* - contains
* - $in['module']
* - An string containig the module name.
* - $in['help_link']
* - A string containing the advanced help path.
* - $in['text']
* - An string containing the help text.
*
* @return the rendered Advanced Help link with the (?) icon.
*/
function gallery_assist_advanced_help_builder($in = array()) {
if (empty($in)) {
return '';
}
$help_link = theme('advanced_help_topic', $in['module'], $in['help_link']);
$output = $help_link ? ' ' . $help_link : '';
$output .= $in['text'];
return $output;
}
/**
* Implementation of hook_node_info().
*/
function gallery_assist_node_info() {
return array(
'gallery_assist' => array(
'name' => t('Gallery'),
'module' => 'gallery_assist',
'description' => t('A gallery is a article type similar in the form to a story or a page and is expanded with gallery functionalities.'),
'has_title' => TRUE,
'title_label' => t('Gallery title'),
'has_body' => TRUE,
'body_label' => t('Gallery Description'),
),
);
}
/**
* Implementation of hook_perm().
*/
function gallery_assist_perm() {
// Access data for the gallery_assist conten type.
$access = array(
'administer gallery_assist',
'view gallery_assist content',
'create gallery_assist content',
'delete own gallery_assist content',
'delete any gallery_assist content',
'edit own gallery_assist content',
'edit any gallery_assist content',
'administer gallery_assist blocks',
);
// Access data for content types with gallery assist assignment.
$assignment_access = array();
$access_holder = array();
$types = node_get_types();
foreach ($types as $v) {
if (variable_get('gallery_assist_' . $v->type, 0) == 1 && $v->type != 'gallery_assist') {
$access_holder[] = array(
'administer gallery_assist_' . $v->type,
'view gallery_assist_' . $v->type . ' content',
'create gallery_assist_' . $v->type . ' content',
'delete own gallery_assist_' . $v->type . ' content',
'delete any gallery_assist_' . $v->type . ' content',
'edit own gallery_assist_' . $v->type . ' content',
'edit any gallery_assist_' . $v->type . ' content',
);
}
}
for ($i = 0; $i < count($access_holder); ++$i) {
$access = array_merge($access, $access_holder[$i]);
}
return $access;
}
/**
* Implementation of hook_access().
*/
function gallery_assist_access($op, $node, $account) {
global $user;
// Manage permissions for the gallery assist content type.
if ($op == 'view' && $node->uid == $user->uid) {
return user_access('view gallery_assist content', $account);
}
if ($op == 'create') {
return user_access('create gallery_assist content', $account);
}
if ($op == 'update') {
if (user_access('edit any gallery_assist content', $account) || user_access('edit own gallery_assist content', $account) && $account->uid == $node->uid) {
return TRUE;
}
}
if ($op == 'delete') {
if (user_access('delete any gallery_assist content', $account) || user_access('delete own gallery_assist content', $account) && $account->uid == $node->uid) {
return TRUE;
}
}
// Manage permissions for conten types with gallery assist assignment.
$types = node_get_types();
foreach ($types as $v) {
if ($op == 'view' && $node->uid == $user->uid) {
return user_access('view gallery_assist_' . $v->type . ' content', $account);
}
if ($op == 'create') {
return user_access('create gallery_assist_' . $v->type . ' content', $account);
}
if ($op == 'update') {
if (user_access('edit any gallery_assist_' . $v->type . ' content', $account) || user_access('edit own gallery_assist_' . $v->type . ' content', $account) && $account->uid == $node->uid) {
return TRUE;
}
}
if ($op == 'delete') {
if (user_access('delete any gallery_assist_' . $v->type . ' content', $account) || user_access('delete own gallery_assist_' . $v->type . ' content', $account) && $account->uid == $node->uid) {
return TRUE;
}
}
}
}
/**
* Implementation of hook_menu().
*/
function gallery_assist_menu() {
$items = array();
// Gallery Assist configuration.
// Principal path.
// Provide infomation about GA an submodules.
$items['admin/settings/gallery_assist'] = array(
'title' => 'Gallery Assist',
'page callback' => 'gallery_assist_info_data',
'access arguments' => array(
'administer gallery_assist',
),
'file' => 'gallery_assist.admin.inc',
'description' => 'Manage the gallery_assist asigments and customize the html output.',
'weight' => 0,
);
// Info tab.
$items['admin/settings/gallery_assist/gallery_assist'] = array(
'title' => 'Info',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
// Assignments.
// Tab containing the node types with assigned Gallery Assist functionality.
$items['admin/settings/gallery_assist/assignments'] = array(
'title' => 'Assignments',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'gallery_assist_settings',
),
'access arguments' => array(
'administer gallery_assist',
),
'file' => 'gallery_assist.admin.inc',
'description' => 'Manage the gallery_assist asigments and customize the html output.',
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
// Assignments.
// The default tab to manage the settings from the module content type (gallery_assist).
$items['admin/settings/gallery_assist/assignments/gallery_assist'] = array(
'title' => 'Gallery Assist',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'gallery_assist_settings',
),
'access arguments' => array(
'administer gallery_assist',
),
'file' => 'gallery_assist.admin.inc',
'description' => 'Manage the gallery_assist assignments and customize the html output.',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
//block/15
// Upload (ahah callback).
$items['gallery_assist_upload/js'] = array(
'page callback' => 'gallery_assist_upload_js',
'access arguments' => array(
'create gallery_assist content',
),
'page arguments' => array(
0,
),
'type' => MENU_CALLBACK,
);
// Menu callbacks for content types with gallery assist assignment.
$types = node_get_types('types');
$i = 1;
foreach ($types as $type) {
if (variable_get('gallery_assist_' . $type->type, 0) == 1 && $type->type != 'gallery_assist') {
// Assignments.
// Additional tabs to manage the settings from content types with assigned gallery functionality.
$items['admin/settings/gallery_assist/assignments/' . $type->type] = array(
'title' => t($type->name),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'gallery_assist_settings',
4,
$type->name,
),
'access arguments' => array(
'administer gallery_assist_' . $type->type,
),
'file' => 'gallery_assist.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => $i,
);
// Gallery_assist assignments: Upload ahah callback.
$items['gallery_assist_' . $type->type . '_upload/js'] = array(
'page callback' => 'gallery_assist_upload_js',
'access arguments' => array(
'create gallery_assist_' . $type->type . ' content',
),
'type' => MENU_CALLBACK,
);
// Gallery_assist assignments: Show the gallery assist short help on any content type.
$items['gallery_assist_' . $type->type . '/help'] = array(
'page callback' => 'gallery_assist_users_help',
'access arguments' => array(
'create gallery_assist_' . $type->type . ' content',
),
'type' => MENU_CALLBACK,
);
// Gallery_assist assignments: Edit one item. This feature is more confortable and faster in case of many gallery_assist items.
$items['node/ga_edit_one_' . $type->type . '/%node/%'] = array(
'title' => t('Gallery Assist'),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'gallery_assist_edit_one',
2,
3,
),
// 'access arguments' => array('create gallery assist '. $type->type .' content'),
'access callback' => 'gallery_assist_check_access',
'access arguments' => array(
2,
'edit',
),
'type' => MENU_CALLBACK,
'weight' => 1000,
);
// Gallery_assist assignments: Save one item ahah callback.
$items['gallery_assist_save_one_' . $type->type . '_js/js/%'] = array(
'page callback' => 'gallery_assist_save_one_js',
'access arguments' => array(
'create gallery_assist_' . $type->type . ' content',
),
'page arguments' => array(
2,
),
'type' => MENU_CALLBACK,
);
}
}
// Extra tab for micelaneous.
// Here are ordered the gallery assignment control, import settings for mass import etc.
$items['admin/settings/gallery_assist/extras'] = array(
'title' => t('Extras'),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'gallery_assist_settings_extras',
),
'access arguments' => array(
'administer gallery_assist',
),
'file' => 'gallery_assist.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 1000,
);
// Default tab.
$items['admin/settings/gallery_assist/extras/extras'] = array(
'title' => t('Extras'),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'gallery_assist_settings_extras',
),
'access arguments' => array(
'administer gallery_assist',
),
'file' => 'gallery_assist.admin.inc',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
// Display a item.
$items['node/%node/%'] = array(
'page callback' => 'gallery_assist_display_item',
'page arguments' => array(
1,
2,
),
'access arguments' => array(
'view gallery_assist content',
),
'type' => MENU_CALLBACK,
);
// Display a item.
$items['node/%node/%/view'] = array(
'title' => t('View'),
'type' => MENU_DEFAULT_LOCAL_TASK,
);
// Display a item.
$items['node/%node/%/edit'] = array(
'title' => t('Edit'),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'gallery_assist_edit_one',
1,
2,
),
'access callback' => 'gallery_assist_check_access',
'access arguments' => array(
1,
'edit',
),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
// Import (ahah callback).
$items['gallery_assist_import/js'] = array(
'page callback' => 'gallery_assist_import_js',
'access arguments' => array(
'create gallery_assist content',
),
'type' => MENU_CALLBACK,
);
// Save one item (ahah callback).
$items['gallery_assist_save_one_js/js/%'] = array(
'page callback' => 'gallery_assist_save_one_js',
'access arguments' => array(
'create gallery_assist content',
),
'page arguments' => array(
2,
),
'type' => MENU_CALLBACK,
);
// Separated help page for users with permissions to create and manage gallery_assist galleries.
$items['gallery_assist/help'] = array(
'page callback' => 'gallery_assist_users_help',
'access arguments' => array(
'create gallery_assist content',
),
'type' => MENU_CALLBACK,
);
// Edit one item.
// This feature is more confortable and faster in case of many gallery_assist items.
$items['node/ga_edit_one/%node/%'] = array(
'title' => t('Gallery Assist'),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'gallery_assist_edit_one',
2,
3,
),
// 'access arguments' => array('create gallery assist content'),
'access callback' => 'gallery_assist_check_access',
'access arguments' => array(
2,
'edit',
),
'type' => MENU_CALLBACK,
'weight' => 1000,
);
// Delete one item.
// This feature is more confortable and faster in case of many gallery_assist items.
$items['node/ga_del_one/%node/%'] = array(
'title' => t('Gallery Assist delete image'),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'gallery_assist_delete_one',
2,
3,
),
// 'access arguments' => array('create gallery assist content'),
'access callback' => 'gallery_assist_check_access',
'access arguments' => array(
2,
'delete',
),
'type' => MENU_CALLBACK,
);
// will come later...
$items['gallery_assist/panic'] = array(
'title' => 'Gallery Assist WARNING!',
'page callback' => 'gallery_assist_panic',
'access arguments' => array(
'administer gallery_assist',
),
'type' => MENU_CALLBACK,
);
// Tab displayed on the user profile containig all galleries from a user.
// For visitors (guest or anonimous) are galleries listed only if the parameter "show in user profile" is seted to TRUE.
$items['user/%user/user_galleries'] = array(
'title' => 'Galleries',
'page callback' => 'gallery_assist_list_galleries',
'page arguments' => array(
1,
),
'access arguments' => array(
'access user profiles',
),
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);
// $items['user/%user/user_galleries2'] = array(
// 'title' => 'Galleries2',
// 'page callback' => 'gallery_assist_list_galleries2',
// 'page arguments' => array(1),
// 'access arguments' => array('access user profiles'),
// 'type' => MENU_LOCAL_TASK,
// 'weight' => 3,
// );
// Node form pager settings.
$items['gallery_assist_form_pager/%'] = array(
'page callback' => 'gallery_assist_form_pager_settings',
'access arguments' => array(
'administer gallery_assist',
),
'page arguments' => array(
1,
),
'type' => MENU_CALLBACK,
'file' => 'gallery_assist.admin.inc',
);
// Set an item to gallery cover.
$items['ga_item_to_cover/%node/%'] = array(
'page callback' => 'gallery_assist_set_item_to_cover',
'page arguments' => array(
1,
2,
),
'access callback' => 'gallery_assist_check_callback_permission',
'access arguments' => array(
1,
2,
),
'type' => MENU_CALLBACK,
);
$items['node/%node/edit/node'] = array(
'title' => 'Article',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
$items['node/%node/edit/ga_sort/no_jquery'] = array(
'title' => 'Sort images',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'gallery_assist_sorting_items_standard',
1,
),
'access callback' => user_access('create gallery_assist content'),
'access arguments' => array(
3,
1,
),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
return $items;
}
/**
* New implementation.
*/
/**
* @TODO: GA: Functionality to check and set the access from GA menus callbacks.
*
* @global <type> $user
* @param <type> $task
* @param <type> $node
* @param <type> $pid
* @return <type>
*/
function gallery_assist_check_callback_permission($task, $node, $pid = NULL) {
global $user;
return TRUE;
}
/**
* Set the gallery cover directly from the gallery page view.
*
* @global <type> $user
* @param <type> $node
* @param <type> $pid
*/
function gallery_assist_set_item_to_cover($node, $pid) {
global $user;
if ($node->gallitems[$pid]->cover == 0) {
gallery_assist_cover_updater($node, $pid);
db_query("DELETE FROM {cache_gallery_assist_data} WHERE cid = %d", $node->nid);
}
$url = $_SERVER['HTTP_REFERER'];
drupal_goto($url);
}
/**
* End new implementation.
*/
/**
* Add to the form the data from the image that will be deleted.
* Menu callback which is activated by clicking on the link delete over the images.
*
* @param Array $form_state
* @param Object $node
* @param Integer $pid
* @return An array containing the form data.
*/
function gallery_assist_delete_one(&$form_state, $node, $pid) {
global $user;
if (gallery_assist_check_access($node, 'delete')) {
$form = array();
$form['gallery_assist_delete_one'] = array(
'#type' => 'fieldset',
'#prefix' => t('<div>Are you sure you want to delete the image %name? If not <a href="@cancel">cancel</a></div>', array(
'%name' => $node->gallitems[$pid]->ptitle,
'@cancel' => url("node/{$node->nid}"),
)),
);
foreach ($node->gallitems[$pid] as $k => $v) {
$form['gallery_assist_delete_one'][$k] = array(
'#type' => 'value',
'#value' => $v,
);
}
$form['gallery_assist_delete_one']['image'] = array(
'#type' => 'item',
'#value' => theme('image', $node->gallitems[$pid]->tpath),
);
// Build the query string to complete the link and so make exact the redirect.
$myPath = array();
$myPath[] = 'node/' . $node->nid;
if ($_GET['page']) {
$myPath[] = 'page=' . $_GET['page'];
}
if ($_GET['titles']) {
$myPath[] = 'titles=' . $_GET['titles'];
}
$form['deleteone'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#name' => 'deleteone',
'#redirect' => $myPath,
);
$form['#submit'][] = 'gallery_assist_delete_one_submit';
$form['#redirect'] = $myPath;
return $form;
}
else {
drupal_access_denied();
}
}
/**
* Action: delete a image and all entries from the db.
*
* @param Array $form
* @param Array $form_state
*/
function gallery_assist_delete_one_submit($form, $form_state) {
$item = $form_state['values'];
//gallery_assist_invalidate_cache($node->nid);
$cq = "DELETE FROM {cache_gallery_assist_data} WHERE cid = '%s'";
db_query($cq, $item['nid']);
$was_cover = $item['cover'] == 1 ? TRUE : FALSE;
// Get the image paths.
$res = db_fetch_object(db_query("SELECT fid, uid, ref, filename, tpath, ppath, opath FROM {gallery_assist_item} WHERE pid=%d", $item['pid']));
// Build the Gallery Assist img path.
$res->thmb_path = variable_get('gallery_assist_directory', file_directory_path() . '/gallery_assist') . '/' . $res->uid . '/gallery_assist' . $res->ref . '/img/' . $res->filename;
if (function_exists('pathauto_menu')) {
if ($form['values']['aid'] > 0) {
db_query("DELETE FROM {url_alias} WHERE pid = %d", $form['values']['aid']);
}
}
// Delete fisicaly the files.
gallery_assist_delete_items($res);
// Delete tables etries, order: files, gallery_assist_translated and gallery_assist_item.
db_query('DELETE FROM {files} WHERE fid = %d', $item['fid']);
db_query('DELETE FROM {gallery_assist_translated} WHERE pid = %d', $item['pid']);
db_query('DELETE FROM {gallery_assist_item} WHERE pid = %d', $item['pid']);
drupal_set_message(t('@title has been successful deleted.', array(
'@title' => $item['ptitle'],
)), 'status');
if ($was_cover) {
drupal_set_message(t('This image was the gallery cover you have to select other image as cover.'), 'warning');
}
$form_state['redirect'] = $form_state['clicked_button']['#redirect'];
}
function gallery_assist_list_galleries2($u) {
global $user;
return count($c) ? $output : t('No galleries');
}
/**
* Gallery list in user profile.
* A owner see all the own galleries, visitors only the selected to be displayed.
*
* @param $u
* A string containing the user object of the node owner.
* @return
* An string containing the galleries as list formated in a table.
*/
function gallery_assist_list_galleries($u) {
global $user;
// Build table header.
$head = array(
array(
'data' => t('Count'),
'field' => 'items',
'class' => 'ga-align-right ga-no-wrap',
),
array(
'data' => t('Cover'),
'class' => 'ga-align-center',
),
array(
'data' => t('Created'),
'field' => 'created',
'sort' => 'desc',
'class' => 'ga_created ga-no-wrap',
),
array(
'data' => t('Updated'),
'field' => 'changed',
'class' => 'ga_created ga-no-wrap',
),
array(
'data' => t('Title'),
'field' => 'title',
'class' => 'ga_titles ga-no-wrap',
),
);
if ($user->uid == 1 || $user->uid == $u->uid) {
$head[] = array(
'data' => t('Operations'),
'class' => 'ga-profile-edit-link',
);
}
else {
$check_profile = 'AND g.in_profile = 1';
}
$query = "SELECT\n g.*,\n n.title, n.type, n.created, n.changed,\n p.pid, p.tpath, t.ptitle\n FROM\n {gallery_assist} g,\n {node} n,\n {gallery_assist_item} p,\n {gallery_assist_translated} t\n WHERE\n g.uid = %d\n AND g.nid = n.nid\n AND g.gref = p.gref\n AND p.pid = t.pid\n AND p.cover = 1" . tablesort_sql($head);
$result = db_query($query, $u->uid);
$c = array();
$edit = 0;
while ($r = db_fetch_object($result)) {
$r->gallconf[$r->type] = unserialize($r->data);
if ($user->uid == 1 || $user->uid == $u->uid || $r->ga_public_status != 1) {
if (gallery_assist_check_access($node)) {
$c[] = $r;
}
if (gallery_assist_check_access($r, 'edit')) {
$edit = $edit + 1;
}
}
}
if (count($c)) {
if ($edit > 0 && ($user->uid == 1 || $user->uid == $u->uid)) {
$head[] = array(
'data' => t('Type'),
'field' => 'type',
'class' => 'ga-profile-type ga-no-wrap',
);
}
$df = t('Y/m/d');
$pstatus = array(
0 => t('public'),
1 => t('privat'),
2 => t('public for all'),
);
foreach ($c as $id => $r) {
$ipath = preg_replace('/thm\\//', 'img/', $r->tpath);
$image = theme('image', $ipath, '', '');
$title = l($r->title, 'node/' . $r->nid) . ($user->uid == 1 || $user->uid == $u->uid ? "<br />({$pstatus[$r->ga_public_status]})" : "");
$rows[$id] = array(
array(
'data' => $r->items,
'class' => 'ga-align-right',
),
//array('data' => l($image, 'node/'. $r->nid .'/'. $r->pid, array('html' => TRUE)), 'class' => 'ga-align-center'),
array(
'data' => l($image, 'node/' . $r->nid, array(
'html' => TRUE,
)),
'class' => 'ga-align-center',
),
array(
'data' => format_date($r->created, 'custom', $df),
),
array(
'data' => format_date($r->changed, 'custom', $df),
),
array(
'data' => $title,
),
);
if ($user->uid == 1 || $user->uid == $u->uid) {
$rows[$id][] = array(
'data' => l(t('edit'), 'node/' . $r->nid . '/edit', array(
'query' => array(
'destination' => 'user/' . $u->uid . '/user_galleries',
),
)),
);
$rows[$id][] = array(
'data' => node_get_types('name', $r->type),
);
}
}
}
$output = theme('table', $head, $rows);
$output .= theme('pager', NULL, 5, $u->uid, NULL, 5);
return count($c) ? $output : t('No galleries');
return '';
}
function ___gallery_assist_list_galleries($u) {
global $user;
// Build table header.
$head = array(
array(
'data' => t('Count'),
'field' => 'counter',
'class' => 'ga-align-right ga-no-wrap',
),
array(
'data' => t('Cover'),
'class' => 'ga-align-center',
),
array(
'data' => t('Created'),
'field' => 'created',
'sort' => 'desc',
'class' => 'ga_created ga-no-wrap',
),
array(
'data' => t('Updated'),
'field' => 'changed',
'class' => 'ga_created ga-no-wrap',
),
array(
'data' => t('Title'),
'field' => 'title',
'class' => 'ga_titles ga-no-wrap',
),
);
if ($user->uid == 1 || $user->uid == $u->uid) {
$head[] = array(
'data' => t('Operations'),
'class' => 'ga-profile-edit-link',
);
}
else {
$check_profile = 'AND g.in_profile = 1';
}
// Get db data.
$query = "SELECT\n g.nid,\n g.gref,\n g.ga_public_status,\n g.data,\n g.items AS counter,\n (SELECT pid FROM {gallery_assist_item} where gref = g.gref order by cover desc limit 1) pid,\n p.tpath,\n n.title,\n n.uid,\n n.type,\n n.created,\n n.changed\n FROM\n {gallery_assist_item} p,\n {gallery_assist} g,\n {node} n\n WHERE\n g.uid = %d\n {$check_profile}\n AND n.nid = g.nid\n AND n.nid = p.nid\n GROUP BY\n g.gref" . tablesort_sql($head);
$result = db_query($query, $u->uid);
$c = array();
$edit = 0;
while ($r = db_fetch_object($result)) {
$r->gallconf[$r->type] = unserialize($r->data);
if ($user->uid == 1 || $user->uid == $u->uid || $r->ga_public_status != 1) {
if (gallery_assist_check_access($node)) {
$c[] = $r;
}
if (gallery_assist_check_access($r, 'edit')) {
$edit = $edit + 1;
}
}
}
if (count($c)) {
if ($edit > 0 && ($user->uid == 1 || $user->uid == $u->uid)) {
$head[] = array(
'data' => t('Type'),
'field' => 'type',
'class' => 'ga-profile-type ga-no-wrap',
);
}
$df = t('Y/m/d');
$pstatus = array(
0 => t('public'),
1 => t('privat'),
2 => t('public for all'),
);
foreach ($c as $id => $r) {
$ipath = preg_replace('/thm\\//', 'img/', $r->tpath);
$image = theme('image', $ipath, '', '');
$title = l($r->title, 'node/' . $r->nid) . ($user->uid == 1 || $user->uid == $u->uid ? "<br />({$pstatus[$r->ga_public_status]})" : "");
$rows[$id] = array(
array(
'data' => $r->counter,
'class' => 'ga-align-right',
),
//array('data' => l($image, 'node/'. $r->nid .'/'. $r->pid, array('html' => TRUE)), 'class' => 'ga-align-center'),
array(
'data' => l($image, 'node/' . $r->nid, array(
'html' => TRUE,
)),
'class' => 'ga-align-center',
),
array(
'data' => format_date($r->created, 'custom', $df),
),
array(
'data' => format_date($r->changed, 'custom', $df),
),
array(
'data' => $title,
),
);
if ($user->uid == 1 || $user->uid == $u->uid) {
$rows[$id][] = array(
'data' => l(t('edit'), 'node/' . $r->nid . '/edit', array(
'query' => array(
'destination' => 'user/' . $u->uid . '/user_galleries',
),
)),
);
$rows[$id][] = array(
'data' => node_get_types('name', $r->type),
);
}
}
}
$output = theme('table', $head, $rows);
$output .= theme('pager', NULL, 5, $u->uid, NULL, 5);
return count($c) ? $output : t('No galleries');
return '';
}
/**
* Implementation of hook_theme().
*/
function gallery_assist_theme() {
return array(
'gallery_assist_form_new' => array(
'arguments' => array(
'form' => NULL,
),
),
'gallery_assist_form_current' => array(
'arguments' => array(
'form' => NULL,
),
),
'gallery_assist_gallery' => array(
'arguments' => array(
'body' => NULL,
'teaser' => FALSE,
'opt' => FALSE,
'owner' => FALSE,
'extras' => FALSE,
),
),
'gallery_assist_display' => array(
'arguments' => array(
'pager' => NULL,
'boxes' => NULL,
'conf' => NULL,
'type' => NULL,
),
),
'gallery_assist_display_list' => array(
'arguments' => array(
'pager' => NULL,
'boxes' => NULL,
'conf' => NULL,
'type' => NULL,
),
),
'gallery_assist_block_display' => array(
'arguments' => array(
'boxes' => NULL,
'conf' => NULL,
'type' => NULL,
'more' => NULL,
),
),
'gallery_assist_item_submitted' => array(
'arguments' => array(
'node' => NULL,
),
),
'gallery_assist_item' => array(
'arguments' => array(
'item' => NULL,
),
),
'gallery_assist_pager' => array(
'arguments' => array(
'node_light' => NULL,
'links' => NULL,
'extras' => NULL,
),
),
'gallery_assist_item_box' => array(
'arguments' => array(
'ga_item_box' => NULL,
'ga_item_title' => NULL,
'ga_edit_link' => NULL,
'ga_item_attr' => NULL,
),
),
'gallery_assist_list_item_box' => array(
'arguments' => array(
'ga_item_box' => NULL,
'ga_item_title' => NULL,
'ga_edit_link' => NULL,
'ga_item_attr' => NULL,
),
),
'gallery_assist_original_download_link' => array(
'arguments' => array(
'item' => NULL,
),
),
'gallery_assist_item_box_list' => array(
'arguments' => array(
'ga_item_list_attr' => NULL,
'ga_item_box' => NULL,
'ga_item_title' => NULL,
'ga_item_copyright' => NULL,
'ga_item_desc' => NULL,
'ga_edit_link' => NULL,
'ga_item_attr' => NULL,
),
),
'gallery_assist_sort_form_current' => array(
'arguments' => array(
'form' => NULL,
),
),
);
}
/**
* Implementation of hook_form().
*/
function gallery_assist_form(&$node, $form_state) {
$type = node_get_types('type', $node);
$form = array();
if ($type->has_title) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -24,
);
}
// The body of gallery assist node type.
if ($type->has_body) {
$form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
$form['body_field']['#weight'] = -20;
$form['body_field']['body']['#rows'] = 5;
}
// // Add a checkbox to lock or unlock the gallery.
// $form['ga_lock'] = array(
// '#type' => 'fieldset',
// '#access' => $node->ga_counter > 300 ? TRUE : FALSE,
// '#weight' => 3000
// );
// $form['ga_lock']['gallery_assist_lockked'] = array(
// '#type' => 'checkbox',
// '#title' => t('One time lock'),
// '#default_value' => FALSE,
// '#description' => t('Enable this parameter to avoid over head or long wait time in case your changes fields that are not part of the gallery. By enabled is all the data from gallery items excluded from the save process.')
// );
return $form;
}
/**
* Implementation of hook_form_alter().
*/
function gallery_assist_form_alter(&$form, &$form_state, $form_id) {
global $user;
$argumente = arg();
// Toggle to show or hide the author information from the image preview.
if ($form_id == 'system_theme_settings' && $argumente[count($argumente) - 1] == 'settings') {
$theme_settings = theme_get_settings();
$types = gallery_assist_get_assignments('all');
foreach ($types as $type => $name) {
if ($type == 'gallery_assist') {
$title = t('Gallery Assist Item preview');
}
else {
$title = t('@name GA Item preview', array(
'@name' => $name,
));
}
$form['node_info']["toggle_node_info_{$type}_item"] = array(
'#type' => 'checkbox',
'#title' => $title,
'#default_value' => $theme_settings["toggle_node_info_{$type}_item"],
);
asort($form['node_info']);
}
}
// Gallery Assist extra user information.
if (arg(0) === 'user' && arg(2) === 'edit' && $form_id == 'user_profile_form') {
if (gallery_assist_check_access($node, 'edit')) {
$form['gallery_assist_user_extras'] = array(
'#type' => 'fieldset',
'#title' => t('Gallery Assist user settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#access' => function_exists('gallery_assist_flickr_form_alter') || function_exists('gallery_assist_picasa_form_alter') ? TRUE : FALSE,
);
}
}
if (isset($form['#node']) && variable_get('gallery_assist_' . $form['#node']->type, 0) == 1 && $form['#node']->type . '_node_form' == $form_id && gallery_assist_check_access($form['#node'], 'edit')) {
$form += _get_ga_form($form);
if (function_exists('pathauto_menu')) {
$form['path']['ga_rebuild_items_alias'] = array(
'#type' => 'checkbox',
'#title' => 'Automatic image aliases',
'#default_value' => $form['#node']->ga_rebuild_items_alias,
);
}
}
unset($this);
}
function _get_ga_form(&$form) {
$node = $form['#node'];
if ($node->type == 'book' && arg(2) == 'outline') {
return;
}
$data = variable_get('gallery_assist_' . $node->type . '_data', FALSE);
if (!isset($node->gallconf) || empty($node->gallconf)) {
$additions = gallery_assist_load($node);
if (!empty($additions)) {
foreach ($additions as $key => $value) {
$node->{$key} = $value;
}
}
}
$form += gallery_assist_form_help_links($node);
$form['ref'] = array(
'#type' => 'hidden',
'#value' => $node->ref ? $node->ref : $node->nid,
);
$form['gref'] = array(
'#type' => 'hidden',
'#value' => $node->gref ? $node->gref : $node->gid,
);
// Note on the order of the process of "create gallery assist node"
$help_path_tail = $node->type == 'gallery_assist' ? '' : '_' . $node->type;
if (arg(1) == 'add') {
global $base_url;
$this['help']['layout'] = array(
'module' => 'gallery_assist',
'help_link' => 'why-save-before-upload',
'text' => t('This article must be saved FIRST before you can add IMAGES to the gallery. Read more about in the <a href="@help_link">help</a>.', array(
'@help_link' => url($base_url . '/gallery_assist' . $help_path_tail . '/help#ga_why'),
)),
);
$form['#prefix'] = variable_get("hide_node_first_notice_for_{$node->type}", FALSE) ? '' : '<div id="gallery-assist-node-info">' . gallery_assist_advanced_help_builder($this['help']['layout']) . '</div>';
}
if (isset($node->nid) && variable_get('gallery_assist_' . $node->type, 0) == 1) {
$this['help']['layout'] = array(
'module' => 'gallery_assist',
'help_link' => 'settings-to-this-gallery',
'text' => t('Read the short help in case you are not secure by this settings.'),
);
$ga_ui_settings = variable_get("gallery_assist_ui_settings", array());
if (!isset($ga_ui_settings[$node->type]) || $ga_ui_settings[$node->type] == 0) {
$form['gallery_assist_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Gallery Assist (GA) settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => $form['title']['#weight'] + 0.5,
);
module_load_include('inc', 'gallery_assist', 'gallery_assist_node_settings');
$form['gallery_assist_settings']['wrapper'] = gallery_assist_settings_tothis_node($node, $data);
if (arg(2) == 'edit') {
if (isset($_GET['page']) && $_GET['page'] > 0) {
$collapsed = FALSE;
}
else {
$collapsed = count($node->gallitems) > 5 ? TRUE : FALSE;
}
}
$node->check_all_links = count($node->gallitems) > 1 ? t('<span class="ga-check-all description">@check_all</span> | <span class="ga-uncheck-all description">@uncheck_all</span>', array(
'@check_all' => t('check all'),
'@uncheck_all' => t('uncheck all'),
)) : '';
// Upload process form section.
$form['gallery_assist_item'] = array(
'#type' => 'fieldset',
'#title' => t('Gallery Assist (GA): Add and edit items') . ' (' . $node->gallconf[$node->type]['ga_counter'] . ')',
'#collapsible' => TRUE,
'#collapsed' => $collapsed,
'#prefix' => '<div class="gallery_assist_list">',
'#suffix' => '</div>',
'#weight' => $form['title']['#weight'] + 1,
'#description' => t('Click Update to upload a new file or to save your changes in this section.<br />') . $node->check_all_links,
);
$form['has_cover'] = array(
'#type' => 'hidden',
'#value' => $node->has_cover,
);
$form['ga_save_caller'] = array(
'#type' => 'hidden',
'#value' => 'node_edit',
);
// 1- node-edit.
$form['gallery_assist_item']['ga_save_caller'] = array(
'#type' => 'hidden',
'#value' => 1,
);
// Wrapper for fieldset contents (used by ahah.js).
$form['gallery_assist_item']['wrapper'] = array(
'#prefix' => '<div id="gallery-assist-list-wrapper">',
'#suffix' => '</div>',
);
// It sends the current user as a reference, if administrators make
// changes in the author information of the node.
$form['gallery_assist_item']['current_owner'] = array(
'#type' => 'value',
'#value' => $node->uid,
);
$form['gallery_assist_item']['wrapper'] += _gallery_assist_form($node);
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['#submit'][] = 'gallery_assist_form_submit';
// Add a checkbox to lock or unlock the gallery.
$form['ga_lock'] = array(
'#type' => 'fieldset',
'#access' => $node->gallconf[$node->type]['ga_counter'] > 100 ? TRUE : FALSE,
'#weight' => 3000,
);
$form['ga_lock']['gallery_assist_lockked'] = array(
'#type' => 'checkbox',
'#title' => t('One time lock'),
'#default_value' => FALSE,
'#description' => t('Enable this parameter to avoid over head or long wait time in case your changes fields that are not part of the gallery. By enabled is all the data from gallery items excluded from the save process.'),
);
}
}
return $form;
}
/**
* Build the form section for upload- and items-administration.
*
* @ingroup forms
*/
function _gallery_assist_form(&$node) {
global $user;
$form = array(
'#theme' => 'gallery_assist_form_new',
'#cache' => TRUE,
'#weight' => 0,
);
if (!empty($node->gallitems) && is_array($node->gallitems)) {
drupal_add_js(drupal_get_path('module', 'gallery_assist') . '/js/gallery_assist.js', 'module', 'footer');
$form['gallery_items']['#theme'] = 'gallery_assist_form_current';
$form['gallery_items']['#tree'] = TRUE;
foreach ($node->gallitems as $key => $item) {
$item = (object) $item;
// Visualize the item image in the form
$img = image_get_info($item->thmb_path);
$top = $img['height'] < 80 ? (80 - $img['height']) / 2 : 0;
$mtop = $img['width'] > $img['height'] ? 'margin-top:' . $top . 'px;' : '';
$item_attr = array(
'style' => 'margin:0;padding:0;border:0;' . $mtop,
);
if (function_exists('imagecache_preset') && $node->gallconf[$node->type]['use_imagecache'] == 1) {
$ic = gallery_assist_get_preset_more_info($node->gallconf[$node->type]['thm_presetid']);
$item->image = theme('imagecache', $node->gallconf[$node->type]['thm_presetname'], $item->opath, $item->palt, $item->ptitle, $item_attr, FALSE);
}
else {
$direction = $img['width'] >= $img['height'] ? 'width' : 'height';
$item->image = theme('image', file_create_url($item->thmb_path), $item->palt, $item->ptitle, $item_attr, FALSE);
}
$item->image_link = '<div class="thmb_form_image" style="width:80px;max-width:80px;height:80px;max-height:80px;margin-left:10px;overflow:hidden;">' . l($item->image, 'node/' . $node->nid . '/' . $item->pid, array(
'html' => TRUE,
)) . '</div>';
$jump_link_text = t('Jump to update-bottom to save the changes');
$changes_warning_text = t('Changes made in this table will be saved by click Update.');
// Item form.
$form['gallery_items'][$key]['remove'] = array(
'#type' => 'checkbox',
'#default_value' => !empty($item->remove),
);
$form['gallery_items'][$key]['item'] = array(
'#value' => $item->image_link,
);
$form['gallery_items'][$key]['ptitle'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#value' => $item->ptitle,
'#prefix' => '<a name="' . $item->pid . '"></a>',
'#suffix' => '<div id="my-edit-gallery-items-' . $item->pid . '-ptitle" style="display:none;" class="warning"><span class="warning">*</span> Changes made in this table will be saved by click Update.</div>',
);
//
$form['gallery_items'][$key]['copyright'] = array(
'#type' => 'textfield',
'#title' => t('Copyright'),
'#size' => '50%',
'#value' => $item->copyright,
'#suffix' => '<div id="my-edit-gallery-items-' . $item->pid . '-copyright" style="display:none;" class="warning"><span class="warning">*</span> Changes made in this table will be saved by click Update.</div>',
);
//
$form['gallery_items'][$key]['pdescription'] = array(
'#type' => 'textarea',
'#rows' => 2,
'#title' => t('Caption'),
'#value' => $item->pdescription,
'#suffix' => '<div id="my-edit-gallery-items-' . $item->pid . '-pdescription" style="display:none;" class="warning"><span class="warning">*</span> ' . $changes_warning_text . '</div><div id="jump-to-update-link" class="jump-to-update-link">' . l($jump_link_text, 'node/' . $item->nid . '/edit', array(
'fragment' => 'update-buttom',
)) . '</div>',
);
//
if (!is_numeric(variable_get('gallery_assist_editform_pager_limit', 'none'))) {
$form['gallery_items'][$key]['weight'] = array(
'#type' => 'weight',
'#delta' => count($node->gallitems),
'#default_value' => $item->weight,
);
}
else {
$form['gallery_items'][$key]['weight'] = array(
'#type' => 'textfield',
'#default_value' => $item->weight,
);
}
$form['gallery_items'][$key]['pid'] = array(
'#type' => 'value',
'#value' => $item->pid,
);
$form['gallery_items'][$key]['cover'] = array(
'#type' => 'hidden',
'#value' => $item->cover,
);
$form['gallery_items'][$key]['gid'] = array(
'#type' => 'hidden',
'#value' => $item->gid,
);
$form['gallery_items'][$key]['new'] = array(
'#type' => 'value',
'#value' => FALSE,
);
$form['gallery_items'][$key]['did'] = array(
'#type' => 'value',
'#value' => $item->did,
);
$form['gallery_items'][$key]['lang'] = array(
'#type' => 'hidden',
'#value' => $node->lang ? $node->lang : $node->language,
);
$form['gallery_items'][$key]['aid'] = array(
'#type' => 'hidden',
'#value' => $item->aid,
);
}
}
$formats = explode(' ', $node->gallconf[$node->type]['extensions']);
$desc = t('Permitted formats: @formats. ', array(
'@formats' => implode(', ', $formats),
));
$pager_limit = variable_get('gallery_assist_editform_pager_limit', 25);
$form['new']['pager_bottom'] = array(
'#type' => 'markup',
'#value' => theme('pager', NULL, $pager_limit, 0, NULL, 5),
'#weight' => 19,
);
$count = $node->gallconf[$node->type]['ga_counter'];
$limit = $node->gallconf[$node->type]['max_form_items'];
if (empty($node->gallconf[$node->type]['max_items'])) {
$display_field = TRUE;
}
elseif ($node->gallconf[$node->type]['max_items'] > $count) {
$diff = $node->gallconf[$node->type]['max_items'] - $count;
$display_field = TRUE;
if ($diff >= $limit) {
$limit = $limit;
}
else {
$limit = $diff;
}
}
else {
$display_field = FALSE;
$limit_message = t('<div id="ga-amount-achaived" class="message warning">' . t('The maximum allowed number of uploads (@max-amount) was achieved.', array(
'@max-amount' => $node->gallconf[$node->type]['max_items'],
)) . '</div>');
}
if ($node->gallconf[$node->type]['user_size'] > 0) {
$used_space = file_space_used($node->uid);
if ($used_space >= $node->gallconf[$node->type]['user_size']) {
$display_field = FALSE;
$limit_message = t('<div id="ga-amount-achaived" class="message warning">' . t('Your disk quota of @quota KB was achieved.', array(
'@quota' => $node->gallconf[$node->type]['user_size'],
)) . '</div>');
}
}
if ($display_field) {
for ($i = 0; $i < $limit; ++$i) {
$form['new']['pictures' . $i] = array(
'#type' => 'file',
'#title' => t('Add new item'),
'#size' => 40,
'#description' => $desc,
'#weight' => 20,
);
}
$help = array(
'module' => 'gallery_assist',
'help_link' => 'add-and-edit-gallery-items',
'text' => t('Enter here the copyright in case all pictures you will just upload and all should having the same copyright.'),
);
$form['new']['temp_copyright'] = array(
'#type' => 'textfield',
'#title' => t('Copyright'),
'#size' => 19,
'#default_value' => $node->temp_copyright,
'#description' => gallery_assist_advanced_help_builder($help),
'#weight' => 22,
);
}
else {
$form['new']['pictures' . $i] = array(
'#type' => 'markup',
'#value' => $limit_message,
'#weight' => 22,
);
}
$form['new']['get_pager_value'] = array(
'#type' => 'hidden',
'#value' => $_GET['page'],
);
$form['new']['picsubmit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#name' => 'picsubmit',
'#ahah' => array(
'path' => $node->type == 'gallery_assist' ? 'gallery_assist_upload/js' : 'gallery_assist_' . $node->type . '_upload/js',
'wrapper' => 'gallery-assist-list-wrapper',
'progress' => array(
'type' => 'bar',
'message' => t('Please wait...'),
),
),
'#submit' => array(
'node_form_submit_build_node',
),
'#prefix' => '<a name="update-buttom"></a>',
'#weight' => 24,
);
unset($node->check_all_links);
return $form;
}
/**
* Theme the "Add and edit items" form.
* Note: required to output prefix/suffix.
*
* @ingroup themeable
*/
function theme_gallery_assist_form_new($form) {
// Define the output as draggable table
if (!is_numeric(variable_get('gallery_assist_editform_pager_limit', 'none'))) {
drupal_add_tabledrag('gallery-assist-list', 'order', 'sibling', 'gallery-assist-weight');
}
$output = drupal_render($form);
return $output;
}
/**
* Theme the item list from the "Add and edit items" form
*
* @ingroup themeable
*/
function theme_gallery_assist_form_current($form) {
$header = array();
//
if (!is_numeric(variable_get('gallery_assist_editform_pager_limit', 'none'))) {
$header[] = '';
}
$header[] = array(
'data' => t('Remove'),
'class' => 'ga-form-delete',
);
$header[] = array(
'data' => t('Image'),
'class' => 'ga-form-item',
);
$header[] = array(
'data' => t('Image info'),
'class' => 'ga-form-caption',
);
if (!is_numeric(variable_get('gallery_assist_editform_pager_limit', 'none'))) {
$header[] = array(
'data' => t('Weight'),
'field' => 'weight',
);
}
else {
$header[] = array(
'data' => t('Weight'),
);
}
// Define the output as draggable table
foreach (element_children($form) as $key) {
if (!is_numeric(variable_get('gallery_assist_editform_pager_limit', 'none'))) {
$row = array(
'',
);
// Add class to group weight fields for drag and drop.
$form[$key]['weight']['#attributes']['class'] = 'gallery-assist-weight';
}
else {
$row = array();
$form[$key]['weight']['#size'] = 5;
}
// Fill the table cells
$row[] = drupal_render($form[$key]['remove']);
$ga_cover = $form[$key]['cover']['#value'] == 1 ? 'ga-cover-bg' : '';
$row[] = array(
'data' => drupal_render($form[$key]['item']),
'class' => $ga_cover,
);
$row[] = drupal_render($form[$key]['ptitle']) . drupal_render($form[$key]['copyright']) . drupal_render($form[$key]['pdescription']);
$row[] = drupal_render($form[$key]['weight']);
if (!is_numeric(variable_get('gallery_assist_editform_pager_limit', 'none'))) {
$row[] = drupal_render($form[$key]['size']);
// Build the row with dragable class
$rows[] = array(
'data' => $row,
'class' => 'draggable',
);
}
else {
// Build the row without dragable class
$rows[] = array(
'data' => $row,
);
}
}
$check_all_links = count($rows) > 1 ? t('<span class="ga-check-all description">@check_all</span> | <span class="ga-uncheck-all description">@uncheck_all</span>', array(
'@check_all' => t('check all'),
'@uncheck_all' => t('uncheck all'),
)) : '';
$output = theme('table', $header, $rows, array(
'id' => 'gallery-assist-list',
)) . $check_all_links;
$output .= drupal_render($form);
return $output;
}
/**
* Set default variables for the new assignment and
* rebuild menus by gallery assist assignment to others content types.
*
* @see gallery_assist_settings_extras()
* @ingroup forms
*/
function gallery_assist_nodetypes_submit(&$form, $form_state) {
$cq = "TRUNCATE TABLE {cache_gallery_assist_data}";
db_query($cq);
$defaults = variable_get('gallery_assist_default_data', array());
$node_types = node_get_types();
unset($node_types['gallery_assist']);
if (variable_get('gallery_assist_upload_method', 'FILE_EXISTS_REPLACE') != $form_state['values']['gallery_assist_upload_method']) {
variable_set('gallery_assist_upload_method', $form_state['values']['gallery_assist_upload_method']);
}
variable_set('gallery_assist_editform_pager_limit', $form_state['values']['gallery_assist_editform_pager_limit']);
variable_set('gallery_assist_forms_possition', $form_state['values']['gallery_assist_forms_possition']);
foreach ($node_types as $type) {
if (variable_get('gallery_assist_' . $type->type, 0) != $form_state['values']['gallery_assist_' . $type->type]) {
if ($form_state['values']['gallery_assist_' . $type->type] == 1) {
variable_set('gallery_assist_' . $type->type, 1);
variable_set('gallery_assist_' . $type->type . '_data', $defaults);
}
else {
variable_set('gallery_assist_' . $type->type, 0);
variable_set('gallery_assist_' . $type->type . '_data', array());
}
}
}
menu_rebuild();
}
/**
* Update the settings of gallery_assist or of assignments.
*
* @see gallery_assist_settings()
*
* @ingroup forms
*/
function gallery_assist_settings_submit(&$form, $form_state) {
//gallery_assist_invalidate_cache();
$cq = "TRUNCATE TABLE {cache_gallery_assist_data}";
db_query($cq);
$type = $form_state['values']['node_type'];
$settings = variable_get('gallery_assist_' . $type . '_data', array());
$gallery_assist_data = $settings;
if ($form_state['values']['gallery_assist_' . $type . '_change'] == TRUE) {
$gallery_assist_update_data = array(
'upload_thm' => check_plain($form_state['values']['gallery_assist_' . $type . '_upload_thm']),
'upload_prev' => check_plain($form_state['values']['gallery_assist_' . $type . '_upload_prev']),
'items_per_row' => $form_state['values']['gallery_assist_' . $type . '_items_per_row'],
't_items_per_row' => $form_state['values']['gallery_assist_' . $type . '_t_items_per_row'],
'rows_per_page' => $form_state['values']['gallery_assist_' . $type . '_rows_per_page'],
'thumbnail_size' => $form_state['values']['gallery_assist_' . $type . '_thumbnail_size'],
'thumbnail_size_plus' => check_plain($form_state['values']['gallery_assist_' . $type . '_thumbnail_size_plus']),
'preview_size' => check_plain($form_state['values']['gallery_assist_' . $type . '_preview_size']),
'item_margin' => $form_state['values']['gallery_assist_' . $type . '_item_margin'],
'item_padding' => $form_state['values']['gallery_assist_' . $type . '_item_padding'],
'item_border' => $form_state['values']['gallery_assist_' . $type . '_item_border'],
'item_border_color' => check_plain($form_state['values']['gallery_assist_' . $type . '_item_border_color']),
'show_backlink' => $form_state['values']['gallery_assist_' . $type . '_show_backlink'],
'show_toggle' => $form_state['values']['gallery_assist_' . $type . '_show_toggle'],
'show_title' => $form_state['values']['gallery_assist_' . $type . '_show_title'],
//
'ga_align' => $form_state['values']['gallery_assist_' . $type . '_ga_align'],
'gap_align' => $form_state['values']['gallery_assist_' . $type . '_gap_align'],
't_ga_float' => $form_state['values']['gallery_assist_' . $type . '_t_ga_float'],
'p_ga_float' => $form_state['values']['gallery_assist_' . $type . '_p_ga_float'],
//
'show_in_homepage_block' => $form_state['values']['gallery_assist_' . $type . '_show_in_homepage_block'],
'position_toggle' => $form_state['values']['gallery_assist_' . $type . '_position_toggle'],
'title_substr' => check_plain($form_state['values']['gallery_assist_' . $type . '_title_substr']),
'pager_symbol' => $form_state['values']['gallery_assist_' . $type . '_pager_symbol'],
'pager_layout' => $form_state['values']['gallery_assist_' . $type . '_pager_layout'],
'pager_position' => $form_state['values']['gallery_assist_' . $type . '_pager_position'],
'pager_visibles' => check_plain($form_state['values']['gallery_assist_' . $type . '_pager_visibles']),
'force_image_height' => $form_state['values']['gallery_assist_' . $type . '_force_image_height'],
'show_download_link' => $form_state['values']['gallery_assist_' . $type . '_show_download_link'],
'use_mbImgNav' => $form_state['values']['gallery_assist_' . $type . '_use_mbImgNav'],
'use_galleria' => $form_state['values']['gallery_assist_' . $type . '_use_galleria'],
'hide_in_teaser' => $form_state['values']['gallery_assist_' . $type . '_hide_in_teaser'],
'item_effect' => $form_state['values']['gallery_assist_' . $type . '_item_effect'],
'max_items' => check_plain($form_state['values']['gallery_assist_' . $type . '_max_items']),
'max_form_items' => check_plain($form_state['values']['gallery_assist_' . $type . '_max_form_items']),
//
'file_size' => $form_state['values']['gallery_assist_' . $type . '_file_size'] * 1024 * 1024,
'user_size' => $form_state['values']['gallery_assist_' . $type . '_user_size'] * 1024 * 1024,
'resolution' => check_plain($form_state['values']['gallery_assist_' . $type . '_resolution']),
'extensions' => check_plain($form_state['values']['gallery_assist_' . $type . '_extensions']),
//
'ga_public_status' => $form_state['values']['gallery_assist_' . $type . '_ga_public_status'],
'admin_public_status' => $form_state['values']['gallery_assist_' . $type . '_admin_public_status'],
'pager_t_height' => check_plain($form_state['values']['gallery_assist_' . $type . '_pager_t_height']),
'pager_t_active_height' => check_plain($form_state['values']['gallery_assist_' . $type . '_pager_t_active_height']),
'pager_presetid' => $form_state['values']['gallery_assist_' . $type . '_pager_presetid'],
'extra_layout_settings_allowed' => $form_state['values']['gallery_assist_' . $type . '_extra_layout_settings_allowed'],
'common_settings_allowed' => $form_state['values']['gallery_assist_' . $type . '_common_settings_allowed'],
'hide_teaser_container_allowed' => $form_state['values']['gallery_assist_' . $type . '_hide_teaser_container_allowed'],
'display_download_link_allowed' => $form_state['values']['gallery_assist_' . $type . '_display_download_link_allowed'],
'container_format_allowed' => $form_state['values']['gallery_assist_' . $type . '_container_format_allowed'],
'gallery_container_weight_allowed' => $form_state['values']['gallery_assist_' . $type . '_gallery_container_weight_allowed'],
'show_in_homepage_block_allowed' => $form_state['values']['gallery_assist_' . $type . '_show_in_homepage_block_allowed'],
'gallery_public_status_allowed' => $form_state['values']['gallery_assist_' . $type . '_gallery_public_status_allowed'],
'show_titles_allowed' => $form_state['values']['gallery_assist_' . $type . '_show_titles_allowed'],
'show_in_userprofile_allowed' => $form_state['values']['gallery_assist_' . $type . '_show_in_userprofile_allowed'],
'gallery_items_shadow_allowed' => $form_state['values']['gallery_assist_' . $type . '_gallery_items_shadow_allowed'],
'gallery_items_shadow' => $form_state['values']['gallery_assist_' . $type . '_gallery_items_shadow'],
'disable_margin_top' => $form_state['values']['gallery_assist_' . $type . '_disable_margin_top'],
'in_profile' => $form_state['values']['gallery_assist_' . $type . '_in_profile'],
'show_layout' => $form_state['values']['gallery_assist_' . $type . '_show_layout'],
'gallery_assist_weight' => $form_state['values']['gallery_assist_' . $type . '_gallery_assist_weight'],
'ga_db_order_field' => $form_state['values']['gallery_assist_' . $type . '_ga_db_order_field'],
'ga_db_order' => $form_state['values']['gallery_assist_' . $type . '_ga_db_order'],
'graphlinks' => $form_state['values']['gallery_assist_' . $type . '_graphlinks'],
'pager_format' => $form_state['values']['gallery_assist_' . $type . '_pager_format'],
'gallery_call_type' => $form_state['values']['gallery_assist_' . $type . '_gallery_call_type'],
'ga_item_title_type' => $form_state['values']['gallery_assist_' . $type . '_ga_item_title_type'],
'pager_align' => $form_state['values']['gallery_assist_' . $type . '_pager_align'],
't_thm_link_format' => $form_state['values']['gallery_assist_' . $type . '_t_thm_link_format'],
'ga_pager_show_pages' => $form_state['values']['gallery_assist_' . $type . '_ga_pager_show_pages'],
'ga_cover_sticky' => $form_state['values']['gallery_assist_' . $type . '_ga_cover_sticky'],
);
if ($form_state['values']['gallery_assist_' . $type . '_show_layout'] == 'list') {
$gallery_assist_update_data['show_title'] = FALSE;
$gallery_assist_update_data['gallery_items_shadow'] = FALSE;
}
if ($form_state['values']['gallery_assist_' . $type . '_ga_public_status_updater'] == 1) {
gallery_assist_public_status_updater($type, $form_state['values']['gallery_assist_' . $type . '_ga_public_status']);
}
variable_set("hide_node_first_notice_for_{$type}", $form_state['values']['gallery_assist_' . $type . '_hide_node_first_notice']);
if (function_exists('imagecache_preset') && is_numeric($form_state['values']['gallery_assist_' . $type . '_pager_presetid'])) {
$preset = imagecache_preset($gallery_assist_update_data['pager_presetid']);
$gallery_assist_update_data['pager_presetname'] = $preset['presetname'];
}
if (function_exists('i18n_menu')) {
$gallery_assist_update_data['translation_behavior'] = $form_state['values']['gallery_assist_' . $type . '_translation_behavior'];
$gallery_assist_update_data['translation_behavior_allowed'] = $form_state['values']['gallery_assist_' . $type . '_translation_behavior_allowed'];
}
if (function_exists('pathauto_menu')) {
$gallery_assist_update_data['build_aliases'] = $form_state['values']['gallery_assist_' . $type . '_build_aliases'];
}
variable_set('gallery_assist_' . $type . '_data', $gallery_assist_update_data);
}
}
/**
* Upload callback over ahah.
* Prepare the data for save and rebuild the form.
*/
function gallery_assist_upload_js() {
$cached_form_state = array();
$items = array();
// Load the form from the Form API cache and print a error message if this process failed.
if (!($cached_form = form_get_cache($_POST['form_build_id'], $cached_form_state)) || !isset($cached_form['#node']) || !isset($cached_form['gallery_assist_item'])) {
form_set_error('form_token', t('Validation error, please try again. If this error persists, please contact the site administrator.' . $cached_form['gallery_assist_item']));
$output = theme('status_messages');
print drupal_to_js(array(
'status' => TRUE,
'data' => $output,
));
exit;
}
// Build the path to satisfy the gallery form pager.
$_GET['q'] = 'node/' . $cached_form['#node']->nid . '/edit';
$_GET['page'] = $_POST['get_pager_value'];
// Build form_state from the POST data.
$form_state = array(
'values' => $_POST,
);
$form_state['gallery_assist_upload_js'] = 1;
$form_state += $_FILES;
$form_state['values']['ga_save_caller'] = 'upload_js';
// Send the data to be processed by upload or update items.
gallery_assist_form_submit($cached_form, $form_state);
// Prepare the updated form.
if (!empty($form_state['values']['gallery_items'])) {
foreach ($form_state['values']['gallery_items'] as $item) {
if (empty($item['remove'])) {
$items[$pid] = $form_state['values']['gallery_items'][$pid];
}
}
}
$node = $cached_form['#node'];
$node = node_load($node->nid);
$node->gall_items = $items;
$form = _gallery_assist_form($node);
unset($cached_form['gallery_assist_item']['wrapper']['new']);
$cached_form['gallery_assist_item']['wrapper'] = array_merge($cached_form['gallery_assist_item']['wrapper'], $form);
$cached_form['gallery_assist_item']['#collapsed'] = FALSE;
form_set_cache($_POST['form_build_id'], $cached_form, $cached_form_state);
foreach ($items as $pid => $item) {
if (is_numeric($pid)) {
$form['gallery_items'][$pid]['ptitle']['#default_value'] = $form_state['values']['gallery_items'][$pid]['ptitle'];
$form['gallery_items'][$pid]['pdescription']['#default_value'] = $form_state['values']['gallery_items'][$pid]['pdescription'];
$form['gallery_items'][$pid]['remove']['#default_value'] = !empty($form_state['values']['gallery_items'][$pid]['remove']);
$form['gallery_items'][$pid]['weight']['#default_value'] = $form_state['values']['gallery_items'][$pid]['weight'];
}
}
$form += array(
'#post' => $_POST,
'#programmed' => FALSE,
'#tree' => FALSE,
'#parents' => array(),
);
// Render the form for output.
$form_id = 'gallery_assist_upload_js';
// drupal_alter('form', $form_state, $form_id);
$data = array(
$form,
$form_state,
$form_id,
);
drupal_alter('form', $data);
$form_state = array(
'submitted' => FALSE,
);
$form = form_builder('gallery_assist_upload_js', $form, $form_state);
$output = theme('status_messages') . drupal_render($form);
// The same as by module upload etc.
// We send the updated file form.
// Don't call drupal_json(). ahah.js uses an iframe and
// the header output by drupal_json() causes problems in some browsers.
print drupal_to_js(array(
'status' => TRUE,
'data' => $output,
));
exit;
}
/**
* Prepare some input keys for save.
*
* @see gallery_assist_upload_js()
*/
function gallery_assist_form_submit(&$form, &$form_state) {
global $user;
$in = $form_state['values'];
$node = $form['#node'];
$node->newfile = $form_state['files'];
$node->temp_copyright = $form_state['values']['temp_copyright'];
$node->gallery_assist_lockked = $form_state['values']['gallery_assist_lockked'];
$node->ga_save_caller = $form_state['values']['ga_save_caller'];
$node->ga_rebuild_items_alias = $form_state['values']['ga_rebuild_items_alias'];
$node->node_path = $form_state['values']['path'];
if (isset($form_state['gallery_assist_upload_js'])) {
$node->gallery_items = $form_state['values']['gallery_items'];
}
else {
$node->gallery_items = $form_state['clicked_button']['#post']['gallery_items'];
}
if (function_exists('pathauto_menu')) {
gallery_assist_rebuild_aliases($node, $form_state['values']);
}
//
if (empty($node->gid)) {
$node->is_new = TRUE;
gallery_assist_insert($node);
drupal_set_message(t('The gallery places had to be recreated. Possible causes: The gallery feature was assigned to this content type after the creation of this article or the gallery-assist module has been reinstalled. In order to be able to upload pictures you have to save this node.'));
}
else {
gallery_assist_save($node, $user);
}
// Clear the GA cache.
$cq = "TRUNCATE TABLE {cache_gallery_assist_data}";
db_query($cq, $node->nid);
}
function gallery_assist_rebuild_aliases($node, $input) {
if ($input['pathauto_perform_alias'] == 1) {
module_load_include('inc', 'pathauto', 'pathauto');
$result = db_query("SELECT p.pid, p.aid, t.ptitle FROM {gallery_assist_item} p, {gallery_assist_translated} t WHERE p.pid = t.pid AND p.nid = %d", $node->nid);
while ($r = db_fetch_array($result)) {
if (empty($r['ptitle'])) {
$ptitle = $r['pid'];
}
else {
$ptitle = $r['ptitle'];
}
$title = drupal_get_path_alias("node/{$node->nid}");
$ptitle = pathauto_cleanstring($ptitle);
$node_path = drupal_get_path_alias("node/{$node->nid}");
$path = array(
'dst' => "{$title}/{$ptitle}-{$r['pid']}",
'language' => $node->language,
'src' => "node/{$node->nid}/{$r['pid']}",
);
if ($r['aid'] > 0) {
$path['pid'] = $r['aid'];
drupal_write_record('url_alias', $path, 'pid');
}
else {
if (isset($path['pid'])) {
unset($path['pid']);
}
drupal_write_record('url_alias', $path);
$new_aid = db_last_insert_id($table, $field);
$gai = array(
'pid' => $r['pid'],
'aid' => $new_aid,
);
drupal_write_record('gallery_assist_item', $gai, 'pid');
}
}
}
else {
if ($input['ga_rebuild_items_alias'] == 1) {
module_load_include('inc', 'pathauto', 'pathauto');
$result = db_query("SELECT p.pid, p.aid, t.ptitle FROM {gallery_assist_item} p, {gallery_assist_translated} t WHERE p.pid = t.pid AND p.nid = %d", $node->nid);
while ($r = db_fetch_array($result)) {
if (empty($r['ptitle'])) {
$ptitle = $r['pid'];
}
else {
$ptitle = $r['ptitle'];
}
if (!empty($node->path)) {
$title = $node->path;
}
else {
$title = "node/{$node->nid}";
}
$ptitle = pathauto_cleanstring($ptitle);
$node_path = drupal_get_path_alias("node/{$node->nid}");
$path = array(
'dst' => "{$title}/{$ptitle}-{$r['pid']}",
'language' => $node->language,
'src' => "node/{$node->nid}/{$r['pid']}",
);
if ($r['aid'] > 0) {
$path['pid'] = $r['aid'];
drupal_write_record('url_alias', $path, 'pid');
}
else {
if (isset($path['pid'])) {
unset($path['pid']);
}
drupal_write_record('url_alias', $path);
$new_aid = db_last_insert_id($table, $field);
$gai = array(
'pid' => $r['pid'],
'aid' => $new_aid,
);
drupal_write_record('gallery_assist_item', $gai, 'pid');
}
}
}
}
}
function gallery_assist_rebuild_alias($item, $x = NULL) {
if ($item->ptitle != $item->old_ptitle) {
module_load_include('inc', 'pathauto', 'pathauto');
if ($item->aid > 0) {
$title = drupal_get_path_alias("node/{$item->nid}");
$ptitle = empty($item->ptitle) ? $item->pid : pathauto_cleanstring($item->ptitle);
$path = array(
'pid' => $item->aid,
'dst' => "{$title}/{$ptitle}-{$item->pid}",
'language' => $item->language,
'src' => "node/{$item->nid}/{$item->pid}",
);
drupal_write_record('url_alias', $path, 'pid');
}
else {
$title = drupal_get_path_alias("node/{$item->nid}");
$ptitle = empty($item->ptitle) ? $item->pid : pathauto_cleanstring($item->ptitle);
$path = array(
'dst' => "{$title}/{$ptitle}-{$item->pid}",
'language' => $item->language,
'src' => "node/{$item->nid}/{$item->pid}",
);
drupal_write_record('url_alias', $path);
$new_aid = db_last_insert_id($table, $field);
$gai = array(
'pid' => $r['pid'],
'aid' => $new_aid,
);
drupal_write_record('gallery_assist_item', $gai, 'pid');
}
}
}
/**
* Allow to edit each Gallery Assist Item separately.
*/
function gallery_assist_edit_one($form_state, $node, $pid) {
// Check if the image exists.
if (!isset($node->gallitems[$pid])) {
drupal_set_message(t('The requested image not exist or is not longer published.'));
drupal_goto('node/' . $node->nid);
}
global $user;
$data = variable_get('gallery_assist_' . $node->type . '_data', FALSE);
if (gallery_assist_check_access($node, 'edit')) {
$conf = $node->gallconf[$node->type];
$form = array();
$breadcrumb = drupal_get_breadcrumb();
$breadcrumb[1] = l($node->title, 'node/' . $node->nid);
$breadcrumb[2] = l($node->gallitems[$pid]->ptitle, 'node/' . $node->nid . '/' . $pid);
drupal_set_breadcrumb($breadcrumb);
drupal_set_title(check_plain($node->title));
if ($conf['show_backlink'] == 1) {
$backlink = l('« ' . t('Back to @ptitle', array(
'@ptitle' => $node->gallitems[$pid]->ptitle,
)), 'node/' . $node->nid . '/' . $pid);
}
$types = node_get_types();
foreach ($types as $type) {
//if (!empty($pid) && array_key_exists($pid, $node->gallitems) && $user->uid == 1 || $user->uid == $node->uid) {
if (!empty($pid) && array_key_exists($pid, $node->gallitems) && gallery_assist_check_access($node, 'edit')) {
$node->pid = $pid;
$node_light = new stdClass();
$links = gallery_assist_item_pager($node, 'edit-one');
$extras['pager_position'] = $conf['pager_position'];
$pager = count($node->gallitems) > 1 ? theme('gallery_assist_pager', $node_light, $links['all'], $extras) : '';
$form['gallery_assist_edit_one'] = array(
'#type' => 'fieldset',
'#title' => t('Edit one item'),
'#prefix' => '<div id="edit-and-save-one-wrapper"></div>',
);
$form['gallery_assist_edit_one']['backlink'] = array(
'#type' => 'markup',
'#value' => $backlink,
);
$form['gallery_assist_edit_one']['pager'] = array(
'#type' => 'markup',
'#value' => $pager,
);
$form['gallery_assist_edit_one']['ptitle'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => $node->gallitems[$pid]->ptitle,
);
$form['gallery_assist_edit_one']['palt'] = array(
'#type' => 'textfield',
'#title' => t('Image alternative text'),
'#default_value' => $node->gallitems[$pid]->palt,
);
$form['gallery_assist_edit_one']['copyright'] = array(
'#type' => 'textfield',
'#title' => t('Copyright'),
'#default_value' => $node->gallitems[$pid]->copyright,
);
$item = new \stdClass();
if (function_exists('imagecache_preset') && $node->gallconf[$node->type]['use_imagecache'] == 1) {
$item->image = theme('imagecache', $node->gallconf[$node->type]['thm_presetname'], $node->gallitems[$pid]->opath, $node->gallitems[$pid]->palt, $node->gallitems[$pid]->ptitle);
}
else {
$item->image = theme('image', file_create_url($node->gallitems[$pid]->tpath), $node->gallitems[$pid]->palt, $node->gallitems[$pid]->ptitle, NULL, FALSE);
}
$item->image_link = l($item->image, 'node/' . $node->nid . '/' . $pid, array(
'html' => TRUE,
));
$form['gallery_assist_edit_one']['pictitle'] = array(
'#type' => 'item',
'#value' => $item->image_link,
);
$form['gallery_assist_edit_one']['pdescription'] = array(
'#type' => 'textarea',
'#title' => t('Caption'),
'#default_value' => $node->gallitems[$pid]->pdescription,
'#rows' => 5,
);
if (!isset($node->gallitems[$pid]->format)) {
$pdescription['format'] = FILTER_FORMAT_DEFAULT;
}
else {
$pdescription['format'] = $node->gallitems[$pid]->format;
}
$form['gallery_assist_edit_one']['format'] = filter_form($pdescription['format']);
$form['gallery_assist_edit_one']['weight'] = array(
'#type' => 'textfield',
'#title' => t('Weight'),
'#default_value' => $node->gallitems[$pid]->weight,
'#size' => 5,
);
$form['gallery_assist_edit_one']['sid'] = array(
'#type' => 'checkbox',
'#title' => t('Allow Download'),
'#default_value' => $node->gallitems[$pid]->sid,
'#disabled' => empty($data['show_download_link']) ? TRUE : FALSE,
'#access' => $data['show_download_link'] ? TRUE : FALSE,
'#size' => 5,
);
$form['gallery_assist_edit_one']['cover'] = array(
'#type' => 'checkbox',
'#title' => t('Gallery-Cover'),
'#description' => t('Set this image to the gallery cover.'),
'#default_value' => $node->gallitems[$pid]->cover,
'#disabled' => $node->gallitems[$pid]->cover,
'#access' => $node->gallitems[$pid]->cover ? FALSE : TRUE,
);
$form['gallery_assist_edit_one']['language'] = array(
'#type' => 'hidden',
'#value' => $node->language,
);
$form['gallery_assist_edit_one']['aid'] = array(
'#type' => 'hidden',
'#value' => $node->gallitems[$pid]->aid,
);
$form['gallery_assist_edit_one']['nid'] = array(
'#type' => 'hidden',
'#value' => $node->nid,
);
$form['gallery_assist_edit_one']['ref'] = array(
'#type' => 'hidden',
'#value' => $node->ref,
);
$form['gallery_assist_edit_one']['pid'] = array(
'#type' => 'hidden',
'#value' => $pid,
);
$form['gallery_assist_edit_one']['fid'] = array(
'#type' => 'hidden',
'#value' => $node->gallitems[$pid]->fid,
);
$form['gallery_assist_edit_one']['node_type'] = array(
'#type' => 'hidden',
'#value' => $node->type,
);
$form['gallery_assist_edit_one']['editone'] = array(
'#type' => 'submit',
'#value' => t('Save and edit'),
'#name' => 'editone',
'#ahah' => array(
'path' => $node->type == 'gallery_assist' ? 'gallery_assist_save_one_js/js/' . $pid : 'gallery_assist_save_one_' . $node->type . '_js/js/' . $pid,
'wrapper' => 'edit-and-save-one-wrapper',
'progress' => array(
'type' => 'bar',
'message' => t('Please wait...'),
),
),
);
$form['gallery_assist_edit_one']['editone2'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#name' => 'editone2',
'#submit' => array(
'gallery_assist_save_one_submit',
),
);
$form['gallery_assist_edit_one']['deleteone'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#name' => 'deleteone',
'#submit' => array(
'gallery_assist_delete_one_submit',
),
'#redirect' => url("node/{$node->nid}"),
);
// Build the query string to complete the link and so make exact the redirect.
$myPath = array();
$myPath[] = 'node/' . $node->nid;
if ($_GET['page']) {
$myPath[] = 'page=' . $_GET['page'];
}
if ($_GET['titles']) {
$myPath[] = 'titles=' . $_GET['titles'];
}
$form['#redirect'] = $myPath;
}
}
return $form;
}
else {
drupal_access_denied();
}
}
function gallery_assist_check_access($node, $op = 'view') {
global $user;
switch ($op) {
case 'view':
if ($user->uid == $node->uid) {
if (user_access('view gallery_assist content') || user_access('view gallery_assist_' . $node->type . ' content')) {
return TRUE;
}
else {
return FALSE;
}
}
else {
if (user_access('view gallery_assist content') || user_access('view gallery_assist_' . $node->type . ' content')) {
if (module_exists('user_relationship_node_access') && $node->ga_public_status == 'ur') {
return gallery_assist_check_ur($node, 'view');
}
else {
return TRUE;
}
}
else {
return FALSE;
}
}
case 'edit':
if ($user->uid == $node->uid) {
if (user_access('edit own gallery_assist content') || user_access('edit own gallery_assist_' . $node->type . ' content')) {
return TRUE;
}
else {
return FALSE;
}
}
else {
if (user_access('edit any gallery_assist content') || user_access('edit any gallery_assist_' . $node->type . ' content')) {
return TRUE;
}
else {
if (module_exists('user_relationship_node_access') && $node->ga_public_status == 'ur') {
return gallery_assist_check_ur($node, 'update');
}
else {
return FALSE;
}
}
}
case 'delete':
if ($user->uid == $node->uid) {
if (user_access('delete own gallery_assist content') || user_access('delete own gallery_assist_' . $node->type . ' content')) {
return TRUE;
}
else {
return FALSE;
}
}
else {
if (user_access('delete any gallery_assist content') || user_access('delete any gallery_assist_' . $node->type . ' content')) {
return TRUE;
}
else {
if (module_exists('user_relationship_node_access') && $node->ga_public_status == 'ur') {
return gallery_assist_check_ur($node, 'delete');
}
else {
return FALSE;
}
}
}
}
}
function gallery_assist_check_ur($node, $op) {
global $user;
if ($user->uid == 1) {
return TRUE;
}
$users = array(
"between" => array(
$node->uid,
$user->uid,
),
);
$get_rel = user_relationships_load($users);
$grant = 0;
foreach ($get_rel as $rel) {
$grant = $grant + $node->user_relationship_node_access[$rel->rtid][$op];
}
if ($grant > 0) {
return TRUE;
}
else {
return FALSE;
}
}
function gallery_assist_save_one_submit(&$form, $form_state) {
$pid = $form_state['values']['pid'];
//$node = db_fetch_object(db_query("SELECT p.nid, g.lang as language, g.data as light_conf FROM {gallery_assist_item} p JOIN {gallery_assist} g ON g.nid = p.nid WHERE p.pid = %d", $pid));
$node = node_load($form_state['values']['nid']);
if (empty($pid)) {
return;
}
else {
if (!$reset) {
//gallery_assist_invalidate_cache($node->nid);
$cq = "DELETE FROM {cache_gallery_assist_data} WHERE cid = '%s'";
db_query($cq, $node->nid);
}
$download = $form_state['values']['sid'] ? 1 : 0;
db_query("UPDATE {gallery_assist_item} SET copyright = '%s', weight = %d, sid = %d WHERE pid = %d", $form_state['values']['copyright'], $form_state['values']['weight'], $download, $pid);
db_query("UPDATE {gallery_assist_translated} SET ptitle = '%s', palt = '%s', pdescription = '%s', format = %d WHERE lang = '%s' AND pid = %d", $form_state['values']['ptitle'], $form_state['values']['palt'], $form_state['values']['pdescription'], $form_state['values']['format'], $form_state['values']['language'], $pid);
$settings = variable_get("gallery_assist_{$form_state['values']['node_type']}_data", array());
if ($form_state['values']['cover'] == 1) {
gallery_assist_cover_updater($node, $pid);
}
if (function_exists('pathauto_menu')) {
$item = $form_state['values'];
$item = (object) $item;
gallery_assist_rebuild_alias($item, $x = NULL);
}
}
$form_state['redirect'] = $form_state['clicked_button']['#redirect'];
}
/**
* Update the cover data by the new and the old cover.
*
* @param integer $nid
* @param integer $pid
*/
function gallery_assist_cover_updater($node, $pid) {
if (is_object($node)) {
$nid = $node->nid;
}
elseif (is_array($node)) {
$nid = $node['nid'];
}
elseif (is_numeric($node)) {
$nid = $node;
}
else {
return;
}
db_query("UPDATE {gallery_assist_item} SET cover = %d WHERE nid = %d", 0, $nid);
db_query("UPDATE {gallery_assist_item} SET cover = %d WHERE pid = %d", 1, $pid);
}
/**
* Save the changes to one item.
*
* @see gallery_assist_edit_one()
*/
function gallery_assist_save_one_js($pid = NULL) {
$cached_form_state = array();
$items = array();
$reset = FALSE;
$node = db_fetch_object(db_query("SELECT p.nid, g.lang as language FROM {gallery_assist_item} p JOIN {gallery_assist} g ON g.nid = p.nid WHERE p.pid = %d", $pid));
$form_state['values'] = $_POST;
$settings = variable_get('gallery_assist_' . $form_state['values']['node_type'] . '_data', array());
if (empty($pid)) {
return;
}
else {
if (!$reset) {
// Clear the GA cache.
$cq = "DELETE FROM {cache_gallery_assist_data} WHERE cid = '%s'";
db_query($cq, $node->nid);
}
$download = $form_state['values']['sid'] ? 1 : 0;
db_query("UPDATE {gallery_assist_item} SET copyright = '%s', weight = %d, sid = %d WHERE pid = %d", $form_state['values']['copyright'], $form_state['values']['weight'], $download, $pid);
db_query("UPDATE {gallery_assist_translated} SET ptitle = '%s', pdescription = '%s', format = %d WHERE lang = '%s' AND pid = %d", $form_state['values']['ptitle'], $form_state['values']['pdescription'], $form_state['values']['format'], $form_state['values']['language'], $pid);
if ($form_state['values']['cover'] == 1) {
gallery_assist_cover_updater($node, $pid);
}
}
print drupal_to_js(array(
'status' => TRUE,
'data' => t('<span class="messages status">Changes sucessfull saved.</span>'),
));
exit;
}
/**
* Implementation of hook_load()
*/
function gallery_assist_load(&$node, $revisions = NULL, $reset = FALSE) {
if (!isset($node->nid)) {
return;
}
global $user;
$nt_conf = variable_get('gallery_assist_' . $node->type . '_data', array());
$args_values = arg();
$pager_limit = arg(3) == 'ga_sort' ? arg(3) : variable_get('gallery_assist_editform_pager_limit', 25);
$ga_c = array();
$nt_ic_conf = array();
if (arg(0) == 'node' && arg(2) == 'edit') {
$reset = TRUE;
}
//$reset = TRUE;
if (!$reset) {
$cache = cache_get($node->nid, 'cache_gallery_assist_data');
}
if (!$reset && !empty($cache->data)) {
$additions = $cache->data;
}
else {
// additions for the node object
$additions = db_fetch_object(db_query("SELECT * FROM {gallery_assist} WHERE nid = %d", $node->nid));
$additions->ga_count = $additions->items;
unset($additions->nid);
// Do nothing when not match's
if (count($additions) == 0) {
return FALSE;
}
$udata = array();
$udata = unserialize($additions->data);
unset($additions->data);
if (empty($udata['ga_db_order_field'])) {
$udata['ga_db_order_field'] = $nt_conf['ga_db_order_field'];
}
if (empty($udata['ga_db_order'])) {
$udata['ga_db_order'] = $nt_conf['ga_db_order'];
}
if ($nt_conf['common_settings_allowed']) {
if ($nt_conf['gallery_public_status_allowed'] != 1) {
$additions->ga_public_status = $nt_conf['ga_public_status'];
}
if (!$nt_conf['container_format_allowed']) {
$udata['show_layout'] = $nt_conf['show_layout'];
}
if (!$nt_conf['gallery_container_weight_allowed']) {
$udata['gallery_container_weight'] = $nt_conf['gallery_container_weight'];
}
if (!$nt_conf['show_in_homepage_block_allowed']) {
$udata['show_in_homepage_block'] = $nt_conf['show_in_homepage_block'];
}
if (!$nt_conf['gallery_public_status_allowed']) {
$additions->ga_public_status = $nt_conf['show_in_homepage_block'];
}
if (!$nt_conf['show_titles_allowed']) {
$udata['show_titles'] = $nt_conf['show_titles'];
$udata['ga_item_title_type'] = $nt_conf['ga_item_title_type'];
}
if (!$nt_conf['show_in_userprofile_allowed']) {
$udata['show_in_userprofile'] = $nt_conf['show_in_userprofile'];
}
if (!$nt_conf['gallery_items_shadow_allowed']) {
$udata['gallery_items_shadow'] = $nt_conf['gallery_items_shadow'];
}
}
if ($nt_conf['extra_layout_settings_allowed'] == 1) {
if (!$nt_conf['hide_teaser_container_allowed']) {
$udata['hide_in_teaser'] = $nt_conf['hide_teaser_container_allowed'];
}
if (!$nt_conf['show_download_link_allowed']) {
$udata['show_download_link'] = $nt_conf['show_download_link'];
}
}
else {
$udata['ga_align'] = $nt_conf['ga_align'];
$udata['gap_align'] = $nt_conf['gap_align'];
$udata['t_ga_float'] = $nt_conf['t_ga_float'];
$udata['p_ga_float'] = $nt_conf['p_ga_float'];
$udata['t_thm_link_format'] = $nt_conf['t_thm_link_format'];
}
$additions->ga_rebuild_items_alias = $udata['ga_rebuild_items_alias'];
unset($udata['ga_rebuild_items_alias']);
// Get gallery items data.
$query_args = array(
$additions->gref,
$node->language,
);
$ga_db_order_field = isset($udata['ga_db_order_field']) ? $udata['ga_db_order_field'] : 'a.weight';
$ga_db_order = isset($udata['ga_db_order']) ? $udata['ga_db_order'] : 'ASC';
$ga_cover_sticky = $nt_conf['ga_cover_sticky'] == 1 ? 'a.cover DESC, ' : '';
$query = "SELECT a.pid, a.nid, a.ref, a.gid, a.gref, a.sid, a.uid, a.fid, a.filename, a.opath,\n a.ppath, a.tpath, a.copyright, a.weight, a.cover, a.aid, f.timestamp, tp.lang, tp.ptitle, tp.palt, tp.pdescription, tp.format,\n tp.did FROM {gallery_assist_item} a JOIN {gallery_assist_translated} tp ON a.pid = tp.pid\n JOIN {files} f ON f.fid = a.fid\n WHERE a.gref=%d AND tp.lang = '%s'";
$query .= " ORDER BY {$ga_cover_sticky} {$ga_db_order_field} {$ga_db_order}";
$query_count = "SELECT count( * ) FROM {gallery_assist_item} a WHERE a.gref=%d";
$items_count = db_result(db_query($query_count, $additions->gref));
if ($pager_limit == arg(3)) {
$pager_limit = $nt_conf['items_per_row'] * $nt_conf['rows_per_page'];
}
if (arg(0) == 'node' && arg(2) == 'edit' && (!isset($args_values[4]) || $args_values[4] != 'no_jquery') && !isset($_GET['unlimited']) && is_numeric(variable_get('gallery_assist_editform_pager_limit', 'none'))) {
if ($items_count > 0) {
$result = pager_query($query, $pager_limit, 0, $query_count, $query_args);
}
}
else {
if ($items_count > 0) {
$result = db_query($query, $query_args);
}
}
// Active languages.
$languages = language_list();
$languages[] = '';
$additions->languages = $languages;
// Build gallconf.
if (variable_get('gallery_assist_' . $node->type, 0) == 1) {
$nt_conf_data = unserialize($nt_conf['data']);
if (function_exists('imagecache_preset') && variable_get('gallery_assist_use_imagecache', 0) == 1) {
$nt_ic_conf = variable_get('gallery_assist_' . $node->type . '_ic_data', array());
$thm_preset = imagecache_preset($nt_ic_conf['thm_presetid']);
$thm_w = $thm_preset['actions'][count($thm_preset['actions']) - 1]['data']['width'];
$thm_h = $thm_preset['actions'][count($thm_preset['actions']) - 1]['data']['height'];
$prev_preset = imagecache_preset($nt_ic_conf['prev_presetid']);
$prev_w = $prev_preset['actions'][count($prev_preset['actions']) - 1]['data']['width'];
$prev_h = $prev_preset['actions'][count($prev_preset['actions']) - 1]['data']['height'];
$nt_conf['thumbnail_size'] = $thm_w >= $thm_h ? $thm_w : $thm_h;
$nt_conf['thumbnail_width_size'] = $thm_w;
$nt_conf['thumbnail_height_size'] = $thm_h;
$nt_conf['preview_size'] = $prev_w >= $prev_w ? $prev_w : $prev_h;
}
else {
$nt_ic_conf = array();
}
}
$ga_c[$node->type] = array_merge($nt_conf, $nt_ic_conf);
$ga_c[$node->type]['ga_counter'] = db_result(db_query("SELECT count( * ) FROM {gallery_assist_item} a WHERE a.gref=%d", $additions->gref));
$ga_c[$node->type]['gallery_items_shadow'] = $udata['gallery_items_shadow'];
$ga_c[$node->type]['ga_item_title_type'] = $udata['ga_item_title_type'];
while ($item = db_fetch_object($result)) {
if ($item->cover == 1) {
$additions->has_cover = $item->pid;
}
$additions->gallitems[$item->pid] = $item;
$additions->gallitems[$item->pid]->thmb_path = preg_replace('/thm\\//', 'img/', $item->tpath);
$additions->gallitems[$item->pid]->download_path = $item->opath;
if (module_exists('transliteration')) {
$additions->gallitems[$item->pid]->tpath = transliteration_get($item->tpath);
$additions->gallitems[$item->pid]->ppath = transliteration_get($item->ppath);
$additions->gallitems[$item->pid]->opath = transliteration_get($item->opath);
$additions->gallitems[$item->pid]->thmb_path = transliteration_get($additions->gallitems[$item->pid]->thmb_path);
}
if (!empty($item->exif)) {
$additions->gallitems[$item->pid]->exif_data = unserialize($additions->gallitems[$item->pid]->exif);
}
// Gallery Assist with imagecache.
if (function_exists('imagecache_preset') && variable_get('gallery_assist_use_imagecache', 0) == 1) {
// Change the thumbnail path to obtain later by display the picture dimentions (margin top).
$additions->gallitems[$item->pid]->tpath = preg_replace('/thm\\//', '', $additions->gallitems[$item->pid]->tpath);
$additions->gallitems[$item->pid]->ppath = preg_replace('/prev\\//', '', $additions->gallitems[$item->pid]->ppath);
$additions->gallitems[$item->pid]->tpath = preg_replace('/files\\/gallery_assist/', 'files/imagecache/' . $ga_c[$node->type]['thm_presetname'] . '/gallery_assist', $additions->gallitems[$item->pid]->tpath);
$additions->gallitems[$item->pid]->ppath = preg_replace('/files\\/gallery_assist/', 'files/imagecache/' . $ga_c[$node->type]['prev_presetname'] . '/gallery_assist', $additions->gallitems[$item->pid]->ppath);
if (!is_file($additions->gallitems[$item->pid]->tpath)) {
$only_load = theme('imagecache', $ga_c[$node->type]['thm_presetname'], $additions->gallitems[$item->pid]->opath);
}
}
// This part repair, recreate thumbnails or preview images if thes are missing or was not created or was deleted etc (gone).
// It is possible only if original images exists.
if (file_exists($additions->gallitems[$item->pid]->opath) && !file_exists($additions->gallitems[$item->pid]->tpath) || !file_exists($additions->gallitems[$item->pid]->ppath) && (variable_get('gallery_assist_use_imagecache', FALSE) == 0 || variable_get('gallery_assist_imagecache_uninstalled', 0) == 1)) {
// drupal_set_message($additions->gallitems[$item->pid]->ptitle .' wurde nicht gefunden', 'warning');
$imageinfo = image_get_info($additions->gallitems[$item->pid]->opath);
$my_dim_ref = $imageinfo['width'] > $imageinfo['height'] ? $imageinfo['width'] : $imageinfo['height'];
$thmb_size = $ga_c[$node->type]['upload_thm'];
$prev_size = $ga_c[$node->type]['upload_prev'];
if (!file_exists($additions->gallitems[$item->pid]->tpath)) {
if ($thmb_size < $my_dim_ref) {
@image_scale($additions->gallitems[$item->pid]->opath, $additions->gallitems[$item->pid]->tpath, $thmb_size, $thmb_size);
}
else {
@copy($additions->gallitems[$item->pid]->opath, $additions->gallitems[$item->pid]->tpath);
}
@chmod($additions->gallitems[$item->pid]->tpath, 0664);
}
if (!file_exists($additions->gallitems[$item->pid]->ppath)) {
if ($prev_size < $my_dim_ref) {
@image_scale($additions->gallitems[$item->pid]->opath, $additions->gallitems[$item->pid]->ppath, $prev_size, $prev_size);
}
else {
@copy($additions->gallitems[$item->pid]->opath, $additions->gallitems[$item->pid]->ppath);
}
@chmod($additions->gallitems[$item->pid]->ppath, 0664);
}
}
}
// Get gallery data.
if (!$additions->ganame) {
$additions->ganame = 'gallery_assist' . isset($additions->ref) ? $additions->ref : $node->nid;
}
$additions->gallery_items_shadow = $udata['gallery_items_shadow'];
$ga_c[$node->type]['show_layout'] = $udata['show_layout'] ? $udata['show_layout'] : $nt_conf['show_layout'];
$ga_c[$node->type]['hide_in_teaser'] = $udata['hide_in_teaser'] ? $udata['hide_in_teaser'] : $nt_conf['hide_in_teaser'];
//$ga_c[$node->type]['show_download_link'] = isset($udata['show_download_link']) ? $udata['show_download_link'] : $nt_conf['show_download_link'];
$ga_c[$node->type]['show_download_link'] = $udata['show_download_link'];
$ga_c[$node->type]['ga_db_order_field'] = $udata['ga_db_order_field'] ? $udata['ga_db_order_field'] : 'weight';
$ga_c[$node->type]['ga_db_order'] = $udata['ga_db_order'] ? $udata['ga_db_order'] : 'DESC';
$ga_c[$node->type]['comments'] = $additions->comments;
$ga_c[$node->type]['ga_align'] = $udata['ga_align'];
$ga_c[$node->type]['gap_align'] = $udata['gap_align'];
$ga_c[$node->type]['t_ga_float'] = $udata['t_ga_float'];
$ga_c[$node->type]['p_ga_float'] = $udata['p_ga_float'];
$ga_c[$node->type]['item_effect'] = $udata['item_effect'] ? $udata['item_effect'] : '';
$ga_c[$node->type]['t_thm_link_format'] = $udata['t_thm_link_format'] ? $udata['t_thm_link_format'] : 'item';
// Calculate needed display format values.
$ga_c[$node->type]['spaces'] = ($ga_c[$node->type]['item_padding'] + $ga_c[$node->type]['item_margin'] + $ga_c[$node->type]['item_border']) * 2;
$ga_c[$node->type]['show_title'] = $additions->show_title;
$ga_c[$node->type]['old_path'] = $udata['old_path'];
if (count($additions->gallitems) < $ga_c[$node->type]['items_per_row']) {
$ga_c[$node->type]['items_per_row'] = count($additions->gallitems);
}
$iprws = is_numeric($ga_c[$node->type]['items_per_row']) ? $ga_c[$node->type]['items_per_row'] : 3;
$t_iprws = is_numeric($ga_c[$node->type]['t_items_per_row']) ? $ga_c[$node->type]['t_items_per_row'] : $iprws;
if ($ga_c[$node->type]['thumbnail_size_plus'] > 0) {
$wplus = $ga_c[$node->type]['thumbnail_size_plus'] * $iprws;
$t_wplus = $ga_c[$node->type]['thumbnail_size_plus'] * $t_iprws;
}
else {
$wplus = 0;
}
$ga_c[$node->type]['container_width'] = ($ga_c[$node->type]['thumbnail_size'] + $ga_c[$node->type]['spaces']) * $iprws + $wplus;
// + 10;
$ga_c[$node->type]['t_container_width'] = ($ga_c[$node->type]['thumbnail_size'] + $ga_c[$node->type]['spaces']) * $t_iprws + 10 + $t_wplus;
if (module_exists('i18n')) {
$ga_c[$node->type]['translation_behavior'] = $udata['translation_behavior'];
}
$additions->gallconf = $ga_c;
if (!$reset) {
cache_set($node->nid, $additions, 'cache_gallery_assist_data');
}
}
// Load the settings of modules which are working with Gallery Assist.
$exteds_result = db_query("SELECT * FROM {gallery_assist_modules_settings} WHERE nid = %d", $node->nid);
while ($r = db_fetch_array($exteds_result)) {
$additions->gallconf[$node->type]['modules'][$r['module']] = $r;
}
return $additions;
}
/**
* Implementation of hook_insert().
*/
function gallery_assist_insert(&$node) {
$count = db_result(db_query("SELECT count(gid) FROM {gallery_assist} WHERE nid=%d", $node->nid));
if ($count > 0) {
return;
}
else {
$my = array();
$av_translation = FALSE;
// if ($node->is_new) {
// $info_text = 'You successfully created your gallery !name. Now you can set various options for this gallery, and add images.<br />When you choose images what you want, you need to press Update button for loading them. <br />When you will ne finished and satisfied with number and description of your images, you need to press button Save on bottom of form, to save all this your work.';
// $box = array(
// '#type' => 'fieldset',
// '#title' => t('Info'),
// '#weight' => 1000,
// '#collapsible' => TRUE
// );
// $box['info_text'] = array(
// '#type' => 'markup',
// '#value' => $info_text
// );
// drupal_set_message(drupal_render($box), 'status');
// }
// Compare and set settings from default.
$data = variable_get('gallery_assist_' . $node->type . '_data', FALSE);
$node->show_title = $data['show_title'];
$settings = array(
'ga_align' => $data['ga_align'],
'gap_align' => $data['gap_align'],
't_ga_float' => $data['t_ga_float'],
'p_ga_float' => $data['p_ga_float'],
'show_layout' => $data['show_layout'],
'gallery_items_shadow' => $data['gallery_items_shadow'],
'show_download_link' => $data['show_download_link'],
'ga_db_order_field' => $data['ga_db_order_field'],
'ga_db_order' => $data['ga_db_order'],
'ga_item_title_type' => $data['ga_item_title_type'],
't_thm_link_format' => $data['t_thm_link_format'],
'ga_public_status' => $data['ga_public_status'],
);
$new_data = serialize($settings);
if (!empty($node->translation_source->nid) || !empty($node->tnid) && $node->tnid > 0) {
// Get ref by tranlation and check and upgrate the translation table
// a exist item will be duplicated with the new language entrie
if (!empty($node->translation_source->nid) || empty($node->tnid)) {
$orig = $node->translation_source;
}
elseif (!empty($node->tnid) || empty($node->translation_source->nid)) {
$count = db_result(db_query("SELECT count(gid) FROM {gallery_assist} WHERE nid=%d", $node->tnid));
if ($count == 0) {
return;
}
$orig = node_load($node->tnid);
}
$my['lang'] = $_GET['language'] ? $_GET['language'] : $node->language;
if (empty($my['lang']) || $my['lang'] == '') {
$my['lang'] = '';
}
if ($node->translation_source->gallconf[$node->type]['translation_behavior'] == 1) {
foreach ($settings as $t_k => $t_v) {
if ($t_k == 'ga_align' || $t_k == 'gap_align' || $t_k == 't_ga_float' || $t_k == 'p_ga_float') {
$t_settings[$t_k] = $node->translation_source->gallconf[$node->type][$t_k];
}
else {
$t_settings[$t_k] = $node->translation_source->gallconf[$node->type][$t_k];
}
}
if (isset($node->translation_source->gallery_items_shadow)) {
$t_settings['gallery_items_shadow'] = $node->translation_source->gallery_items_shadow;
}
if (isset($node->translation_source->gallconf[$node->type]['ga_db_order_field'])) {
$t_settings['ga_db_order_field'] = $node->translation_source->gallconf[$node->type]['ga_db_order_field'];
}
if (isset($node->translation_source->gallconf[$node->type]['ga_db_order'])) {
$t_settings['ga_db_order'] = $node->translation_source->gallconf[$node->type]['ga_db_order'];
}
if (isset($node->translation_source->gallconf[$node->type]['hide_in_teaser'])) {
$t_settings['hide_in_teaser'] = $node->translation_source->gallconf[$node->type]['hide_in_teaser'];
}
if (isset($node->translation_source->gallconf[$node->type]['hide_in_teaser'])) {
$t_settings['translation_behavior'] = $node->translation_source->gallconf[$node->type]['translation_behavior'];
}
$new_data = serialize($t_settings);
}
if (count($orig->gallitems) > 0) {
foreach ($orig->gallitems as $pid => $item) {
$insert_translated_data = array(
'nid' => $node->nid,
'gid' => $item->gid,
'gref' => $item->gref,
'pid' => $pid,
'lang' => $my['lang'],
'ptitle' => $item->ptitle,
'palt' => $item->ptitle,
'pdescription' => $item->pdescription,
);
drupal_write_record('gallery_assist_translated', $insert_translated_data);
}
}
$my['gref'] = $orig->gref ? $orig->gref : $orig->gid;
$node->in_profile = $orig->in_profile;
$node->ga_public_status = $orig->ga_public_status;
$node->show_title = $orig->show_title;
$av_translation = TRUE;
$cq = "DELETE FROM {cache_gallery_assist_data} WHERE cid = '%s'";
db_query($cq, $node->tnid);
}
// Create a new gallery assist as new node or as referenced tranlated node.
// are normaly nodes
$my['ref'] = $orig->ref ? $orig->ref : $node->nid;
if ($node->sepparated == 1) {
$my['lang'] = $_GET['language'] ? $_GET['language'] : $node->language;
$my['ganame'] = 'gallery_assist' . $node->nid;
$my['ref'] = $node->nid;
$node->in_profile = '';
$node->ga_public_status = '';
$node->show_title = '';
}
else {
$my['lang'] = $_GET['language'] ? $_GET['language'] : $node->language;
$my['ganame'] = $node->ganame ? $node->ganame : 'gallery_assist' . $my['ref'];
}
$insert_gallery_data = array(
'ref' => $my['ref'],
'gref' => isset($my['gref']) ? $my['gref'] : (int) 0,
'lang' => $my['lang'],
'nid' => $node->nid,
'uid' => $node->uid,
'ganame' => $my['ganame'],
'in_profile' => isset($node->in_profile) ? $node->in_profile : $data['in_profile'],
'ga_public_status' => $data['ga_public_status'],
'show_title' => isset($node->show_title) ? $node->show_title : $data['show_title'],
'show_in_homepage_block' => isset($node->show_in_homepage_block) ? $node->show_in_homepage_block : $data['show_in_homepage_block'],
'gallery_assist_weight' => $data['gallery_assist_weight'] ? $data['gallery_assist_weight'] : $node->gallery_assist_weight,
'data' => $new_data,
);
if ($node->translation_source->gallconf[$node->type]['translation_behavior'] == 1) {
if (isset($node->translation_source->gallery_assist_weight)) {
$insert_gallery_data['gallery_assist_weight'] = $node->translation_source->gallery_assist_weight;
}
if (isset($node->translation_source->show_in_homepage_block)) {
$insert_gallery_data['show_in_homepage_block'] = $node->translation_source->show_in_homepage_block;
}
}
drupal_write_record('gallery_assist', $insert_gallery_data);
// Get the gid for other operations.
$my['last_gid'] = db_last_insert_id('gallery_assist', 'gid');
if ($my['ref'] == $node->nid) {
// If realy new gallery reference self. Important in case the site will be multilingual, will be translated.
$update_gallery_data = array(
'gref' => $my['last_gid'],
'nid' => $node->nid,
);
drupal_write_record('gallery_assist', $update_gallery_data, 'nid');
}
if ($node->translation_source->gallconf[$node->type]['translation_behavior'] == 1) {
// Check if exists settings from other submodules.
if (count($node->translation_source->gallconf[$node->type]['modules']) > 0) {
foreach ($node->translation_source->gallconf[$node->type]['modules'] as $module => $settings) {
$insert_gallery_data;
$settings_record = array(
'nid' => $node->nid,
'ref' => $node->translation_source->ref,
'gid' => $my['last_gid'],
'gref' => $node->translation_source->gref,
'module' => $module,
'data' => $node->translation_source->gallconf[$node->type]['modules'][$module]['data'],
);
db_query("insert into {gallery_assist_modules_settings} (nid, ref, gid, gref, module, data)\n VALUES (%d, %d, %d, %d, '%s', '%s')", $settings_record['nid'], $settings_record['ref'], $settings_record['gid'], $settings_record['gref'], $settings_record['module'], $settings_record['data']);
}
}
}
if ($av_translation) {
$cq = "DELETE FROM {cache_gallery_assist_data} WHERE cid = '%s'";
db_query($cq, $node->nid);
}
unset($my);
}
}
/**
* Implementation of hook_update().
*/
function gallery_assist_update($node) {
if (arg(2) == 'revisions' && (arg(4) == 'revert' || arg(4) == 'delete')) {
return;
}
$ui = variable_get('gallery_assist_ui_settings', array());
if (isset($ui[$node->type]) && $ui[$node->type] == 1 && arg(3) != 'ga_settings') {
return;
}
$cq = "DELETE FROM {cache_gallery_assist_data} WHERE cid = '%s'";
db_query($cq, $node->nid);
// Get data from principal gallery (the origen node from the translation)
$q = db_query("SELECT gid, gref, lang FROM {gallery_assist} WHERE ref = %d", $node->ref);
// Save the settings to origen and translated galleries
if (!empty($node->in_profile)) {
$my_in_profile = 1;
}
else {
$my_in_profile = 0;
}
if (!empty($node->show_title)) {
$my_show_title = 1;
}
else {
$my_show_title = 0;
}
if (!empty($node->gallery_items_shadow)) {
$shadow = 1;
}
else {
$shadow = 0;
}
// Update data.
$d_settings = variable_get('gallery_assist_' . $node->type . '_data', FALSE);
$settings = array();
if ($d_settings['common_settings_allowed']) {
if ($d_settings['gallery_public_status_allowed']) {
$settings['ga_public_status'] = $node->ga_public_status;
}
else {
$settings['ga_public_status'] = $d_settings['ga_public_status'];
}
if ($d_settings['container_format_allowed']) {
$settings['show_layout'] = $node->show_layout;
}
else {
$settings['show_layout'] = $d_settings['show_layout'];
}
if ($d_settings['gallery_container_weight_allowed']) {
$settings['gallery_container_weight'] = $node->gallery_container_weight;
}
else {
$settings['gallery_container_weight'] = $d_settings['gallery_container_weight'];
}
if ($d_settings['show_in_homepage_block_allowed']) {
$settings['show_in_homepage_block'] = $node->show_in_homepage_block;
}
else {
$settings['show_in_homepage_block'] = $d_settings['show_in_homepage_block'];
}
if ($d_settings['gallery_public_status_allowed']) {
$settings['gallery_public_status'] = $node->gallery_public_status;
}
else {
$node->gallery_public_status = $d_settings['show_in_homepage_block'];
}
if ($d_settings['show_titles_allowed']) {
$settings['show_titles'] = $node->show_titles;
$settings['ga_item_title_type'] = $node->ga_item_title_type;
}
else {
$settings['show_titles'] = $d_settings['show_titles'];
$settings['ga_item_title_type'] = $d_settings['ga_item_title_type'];
}
if ($d_settings['show_in_userprofile_allowed']) {
$settings['show_in_userprofile'] = $node->show_in_userprofile;
}
else {
$settings['show_in_userprofile'] = $d_settings['show_in_userprofile'];
}
if ($d_settings['gallery_items_shadow_allowed']) {
$settings['gallery_items_shadow'] = $node->gallery_items_shadow;
}
else {
$settings['gallery_items_shadow'] = $d_settings['gallery_items_shadow'];
}
}
if ($d_settings['extra_layout_settings_allowed'] == 1) {
$settings['ga_align'] = $node->ga_align;
$settings['gap_align'] = $node->gap_align;
$settings['t_ga_float'] = $node->t_ga_float;
$settings['p_ga_float'] = $node->p_ga_float;
$settings['t_thm_link_format'] = $node->t_thm_link_format;
if ($d_settings['hide_teaser_container_allowed']) {
$settings['hide_in_teaser'] = $node->hide_in_teaser;
}
else {
$settings['hide_in_teaser'] = $d_settings['hide_teaser_container_allowed'];
}
if ($d_settings['show_download_link_allowed']) {
$settings['show_download_link'] = $node->show_download_link;
}
else {
$settings['show_download_link'] = $d_settings['show_download_link'];
}
}
$settings['ga_db_order_field'] = $node->ga_db_order_field;
$settings['ga_db_order'] = $node->ga_db_order;
if (module_exists('i18n')) {
$settings['translation_behavior'] = $node->translation_behavior;
}
if (!empty($node->path)) {
$settings['old_path'] = $node->path;
}
if (function_exists('pathauto_menu')) {
$settings['ga_rebuild_items_alias'] = $node->ga_rebuild_items_alias;
}
if ($settings['show_layout'] == 'list') {
$settings['show_title'] = FALSE;
$settings['gallery_items_shadow'] = FALSE;
}
$new_data = serialize($settings);
// If the owner is changed.
// Realize all nedded operations to assiggn all files and all galleries informations to the new owner.
// Last fix to "Deleted folders after change of author" thanks suffering_drupal.
if (!empty($node->current_owner) && is_numeric($node->current_owner) && $node->uid != $node->current_owner) {
$the_new_user = user_load($node->uid);
$new_user_gallery_directory = variable_get('gallery_assist_directory', file_directory_path() . '/gallery_assist') . '/' . $node->uid;
$old_user_gallery_directory = variable_get('gallery_assist_directory', file_directory_path() . '/gallery_assist') . '/' . $node->current_owner;
if (!is_dir($new_user_gallery_directory)) {
if (!file_check_directory($new_user_gallery_directory, 1)) {
drupal_set_message('Konte new_user_gallery_directory nicht erstellen.');
}
}
if (is_dir($new_user_gallery_directory)) {
gallery_assist_makedirs($node);
if (count($node->gallery_items) > 0) {
$old_path = "gallery_assist/{$node->current_owner}/";
$new_path = "gallery_assist/{$node->uid}/";
// Get the reference gid and change all paths in the item table.
$gref = db_result(db_query("SELECT gref FROM {gallery_assist} WHERE ref = %d", $node->ref));
$q_change = "UPDATE {gallery_assist_item} SET opath = replace( opath , '%s', '%s' ),\n ppath = replace( ppath , '%s', '%s' ),\n tpath = replace( tpath , '%s', '%s' ),\n uid = %d WHERE gref = %d";
if (!db_query($q_change, db_escape_string($old_path), db_escape_string($new_path), db_escape_string($old_path), db_escape_string($new_path), db_escape_string($old_path), db_escape_string($new_path), $node->uid, $gref)) {
drupal_set_message(t('A error is ocurred by Gallery Assist owner change'), 'error');
}
// Scan for moving proccess.
$get_old_path = $old_user_gallery_directory . '/gallery_assist' . $node->nid;
$move_to_path = $new_user_gallery_directory . '/gallery_assist' . $node->nid;
$scann = file_scan_directory($get_old_path, '.', array(), 0, TRUE);
// Move the files to the new destination.
foreach ($scann as $v) {
$new_place = preg_replace("/\\/{$v->basename}/", '', $v->filename);
$new_place = preg_replace("/\\/{$node->current_owner}\\//", "/{$node->uid}/", $new_place);
file_move($v->filename, $new_place, $replace = FILE_EXISTS_REPLACE);
}
// Update the paths in the files table.
foreach ($node->gallery_items as $item) {
$q_f_change = "UPDATE {files} SET filepath = replace( filepath , '%s', '%s' ), uid = %d WHERE uid = %d AND fid = %d";
db_query($q_f_change, db_escape_string($old_path), db_escape_string($new_path), $node->uid, $node->current_owner, $item['fid']);
}
}
// Delete the old gallery folder.
if (gallery_assist_delete_directory(file_directory_path() . '/gallery_assist/' . $node->current_owner . '/gallery_assist' . $node->nid)) {
drupal_set_message(t('<b>The new owner of this gallery is user: @uname</b>', array(
'@uname' => $node->name,
)));
}
}
if ($node->uid > 1) {
if (!user_access('create gallery_assist content', $the_new_user) || !user_access('create gallery_assist ' . $node->type . ' content', $the_new_user)) {
$bla = user_access('create gallery_assist_' . $node->type . ' content', $the_new_user);
$ble = user_access('create gallery_assist content', $the_new_user);
$s = $bla + $ble;
if ($s == 0) {
drupal_set_message(t("<strong>A T T E N T I O N !</strong><br /> The user @uname haven't the needed permissions to create or edit this node type.", array(
'@uname' => $node->name,
)), 'warning');
}
}
}
}
// The owner is changed END.
// Update settings on original and on each translation node.
while ($res = db_fetch_object($q)) {
$update_data = array(
'gid' => $res->gid,
'uid' => $node->uid,
'in_profile' => $my_in_profile,
'ga_public_status' => $node->ga_public_status,
'show_title' => $my_show_title,
'gallery_assist_weight' => $node->gallery_assist_weight,
'show_in_homepage_block' => $node->show_in_homepage_block,
'data' => $new_data,
'items' => db_result(db_query("SELECT COUNT(*) FROM {gallery_assist_item} WHERE gref = %d", $node->gref)),
);
drupal_write_record('gallery_assist', $update_data, 'gid');
}
if ($node->show_download_link != $node->show_download_link_old) {
$update_p_data = array(
'ref' => $node->ref,
'sid' => $node->show_download_link,
);
drupal_write_record('gallery_assist_item', $update_p_data, 'ref');
}
// If just translated, update all.
if ($node->language != db_result(db_query("SELECT lang FROM {gallery_assist} WHERE nid = %d", $node->nid))) {
$update_t_data = array(
'nid' => $node->nid,
'uid' => $node->uid,
'lang' => $node->language,
);
drupal_write_record('gallery_assist', $update_t_data, 'nid');
$update_translated_data = array(
'nid' => $node->nid,
'uid' => $node->uid,
'lang' => $node->language,
);
drupal_write_record('gallery_assist_translated', $update_translated_data, 'nid');
}
// Save the settings data from modules that are working with Gallery Assist.
foreach (module_implements('gallery_assist_api') as $name) {
$function = $name . '_gallery_assist_api';
$get_data = $node->{$name};
$gam_data = serialize($get_data);
$key_name = 'gam_' . $name;
$gam = $node->{$key_name};
if (isset($gam) && $gam > 0) {
$record = array(
'gam' => $gam,
'nid' => $node->nid,
'ref' => $node->ref,
'gid' => $node->gid,
'gref' => $node->gref,
'module' => $name,
'data' => $gam_data,
);
drupal_write_record('gallery_assist_modules_settings', $record, 'gam');
}
else {
$q = db_query("insert into {gallery_assist_modules_settings} (nid, ref, gid, gref, module, data)\n VALUES (%d, %d, %d, %d, '%s', '%s')", $node->nid, $node->ref, $node->gid, $node->gref, $name, $gam_data);
}
}
// if (count($node->gallery_items) > 0 && empty($node->has_cover)) {
// drupal_set_message('Currently, this gallery has no cover. Please choose one.', 'warning');
// }
}
/**
* Implementation of hook_save().
*/
function gallery_assist_save(&$node, $u = '') {
if ($node->gallery_assist_lockked) {
return;
}
$cq = "DELETE FROM {cache_gallery_assist_data} WHERE cid = '%s'";
db_query($cq, $node->nid);
if (empty($u)) {
global $user;
}
else {
$user = user_load($u);
}
// Update or delete items data.
if (count($node->gallery_items) > 0) {
foreach ($node->gallery_items as $pid => $item) {
$item = (object) $item;
$pa_op = 'update';
// Remove Item.
if (!empty($item->remove)) {
$pa_op = 'delete';
// Get paths and fid from gallery_assist_item.
$res = db_fetch_object(db_query("SELECT fid, uid, ref, filename, tpath, ppath, opath FROM {gallery_assist_item} WHERE pid=%d", $pid));
// Delete fisicaly the files.
$res->thmb_path = variable_get('gallery_assist_directory', file_directory_path() . '/gallery_assist') . '/' . $res->uid . '/gallery_assist' . $res->ref . '/img/' . $res->filename;
gallery_assist_delete_items($res);
// Delete tables etries, order: files, gallery_assist_translated and gallery_assist_item.
db_query('DELETE FROM {files} WHERE fid = %d', $res->fid);
db_query('DELETE FROM {gallery_assist_translated} WHERE pid = %d', $pid);
db_query('DELETE FROM {gallery_assist_item} WHERE pid = %d', $pid);
drupal_set_message(t('@title has been successful deleted.', array(
'@title' => $item->ptitle,
)), 'status');
// Send information to other modules when a image will be deleted.
$node_light = new \stdClass();
$node_light->pid = $pid;
$node_light->nid = $node->nid;
$node_light->nid = $node->ref;
foreach (module_implements('gallery_assist_api') as $name) {
$function = $name . '_gallery_assist_api';
$result = $function('item_delete', $pid, $node_light);
}
}
if ($node->temp_copyright) {
$item->copyright = $node->temp_copyright;
}
// Update items data.
$update_item_data = array(
'pid' => $pid,
'copyright' => $item->copyright,
'weight' => $item->weight,
);
drupal_write_record('gallery_assist_item', $update_item_data, 'pid');
$update_translated_data = array(
'pid' => $pid,
'lang' => $node->language,
'ptitle' => $item->ptitle,
'pdescription' => empty($item->pdescription) ? '' : $item->pdescription,
);
drupal_write_record('gallery_assist_translated', $update_translated_data, array(
'pid',
'lang',
));
if (function_exists('pathauto_menu')) {
$item->pid = $pid;
$item->old_ptitle = $node->gallitems[$pid]->ptitle;
$item->nid = $node->nid;
$item->language = $node->language;
gallery_assist_rebuild_alias($item, $x = NULL);
}
}
}
if (count($node->newfile['name']) > 0) {
$w = db_result(db_query("SELECT weight FROM {gallery_assist_item} WHERE gref = %d ORDER BY weight DESC LIMIT 1", $node->gref));
for ($i = 0; $i < count($node->newfile['name']); ++$i) {
// Increment the weight value.
$w = $w + 1;
// Set the first uploaded image as cover.
$node->has_cover = db_result(db_query("SELECT pid FROM {gallery_assist_item} WHERE gref = %d AND cover = %d", $node->gref, 1));
if (empty($node->has_cover)) {
$cover = 1;
}
else {
$cover = 0;
}
if (!empty($node->newfile['name']['pictures' . $i])) {
$upload_dir = variable_get('gallery_assist_directory', file_directory_path() . '/gallery_assist') . '/' . $node->uid . '/' . $node->ganame;
// Found supported packages will be sended to upport.
$imp_ext = substr(strrchr($node->newfile['name']['pictures' . $i], '.'), 1);
$imp_ext = strtolower($imp_ext);
// Upport.
if (module_exists('gallery_assist_upport') && user_access('allow upport zip upload')) {
++$zip_counter;
//if (user_access('use zip upload on '. $node->type) && ($imp_ext == 'zip' || $imp_ext == 'rar' || $imp_ext == 'tar' || $imp_ext == 'tar.gz')) {
if ($user->uid == 1 || $imp_ext == 'zip') {
if ($imp_ext == 'tar' || $imp_ext == 'tar.gz' || $imp_ext == 'rar') {
drupal_set_message('Currently are the formate tar, tar.gz and rar not supported.', 'warning');
next;
}
++$zip_counter;
$arch = $node->newfile['name']['pictures' . $i];
$import_dir = variable_get('gallery_assist_directory', file_directory_path() . '/gallery_assist') . '/' . $node->uid . '/import';
$import_tmp = variable_get('gallery_assist_directory', file_directory_path() . '/gallery_assist') . '/' . $node->uid . '/import/tmp';
file_check_directory($import_dir, 1);
@chmod($import_dir, 0777);
file_check_directory($import_tmp, 1);
@chmod($import_tmp, 0777);
$arch_validators = array(
'file_validate_extensions' => array(
'zip',
),
'file_validate_size' => array(
$node->gallconf[$node->type]['file_size'],
$node->gallconf[$node->type]['user_size'],
),
);
$arch_file = file_save_upload('pictures' . $i, $arch_validators, $import_dir, $replace = FILE_EXISTS_REPLACE);
if (!empty($arch_file->filepath)) {
if (module_exists('gallery_assist_upport')) {
$node->gall_imports['arch']['zip'][] = $arch_file->filepath;
$import_message = gallery_assist_upport_archiv_save($node);
drupal_set_message($import_message);
db_query("DELETE FROM {files} WHERE fid = %d", $arch_file->fid);
}
}
else {
drupal_set_message(t('Archive @zip_name but the module <a href="@upport_url">Gallery Assist Upport</a> is not installed. The archiv would uploaded to the specific folder and is ready to import to a gallery by upport installing.', array(
'@zip_name' => $node->newfile['name']['pictures' . $i],
'@upport_url' => url('drupal.org/project/gallery_assist_upport'),
)));
}
unset($node->newfile['name']['pictures' . $i]);
next;
}
}
// End of upport preprocess.
if ((user_access('create gallery_assist content') || user_access('create gallery_assist_' . $node->type . ' content')) && !is_dir($upload_dir || !is_dir($upload_dir . '/img') || !is_dir($upload_dir . '/thm') || !is_dir($upload_dir . '/prev'))) {
gallery_assist_makedirs($node);
}
// separe file name and file extension.
$f_ext_string = substr(strrchr($node->newfile['name']['pictures' . $i], '.'), 0);
$f_name_string = preg_replace('/\\.[a-z0-9]+$/i', '', $node->newfile['name']['pictures' . $i]);
$my_ptitle = $f_name_string;
if (file_create_path($upload_dir, 1)) {
$validators = array(
'file_validate_is_image' => array(),
);
if (!empty($node->gallconf[$node->type]['extensions'])) {
$validators['file_validate_extensions'] = array(
$node->gallconf[$node->type]['extensions'],
);
}
if (!empty($node->gallconf[$node->type]['resolution'])) {
$validators['file_validate_image_resolution'] = array(
$node->gallconf[$node->type]['resolution'],
);
}
if (!empty($node->gallconf[$node->type]['file_size']) || $node->gallconf[$node->type]['file_size'] > 0) {
$validators['file_validate_size'] = array(
$node->gallconf[$node->type]['file_size'],
$node->gallconf[$node->type]['user_size'],
);
}
if (is_dir($upload_dir) && $node->newfile['name']['pictures' . $i]) {
$replace = variable_get('gallery_assist_upload_method', 1) == 1 ? TRUE : FALSE;
// In case the file exists remove al derivatives.
// So can the module write the new files.
$replaced = FALSE;
if ($replace == 1 && file_exists($upload_dir . '/' . $node->newfile['name']['pictures' . $i])) {
// drupal_set_message(t('Files are be replaced. In case you see the old files, you see only from the cache of your browser. <br />By reload you can see the just uploaded.'));
drupal_set_message(t('Replace file: @file.', array(
'@file' => $node->newfile['name']['pictures' . $i],
)));
if (file_exists($upload_dir . '/' . $node->newfile['name']['pictures' . $i])) {
file_delete($upload_dir . '/' . $node->newfile['name']['pictures' . $i]);
$p_i_d = db_fetch_object(db_query("SELECT fid, pid FROM {gallery_assist_item} WHERE opath = '%s'", $upload_dir . '/' . $node->newfile['name']['pictures' . $i]));
if (!empty($p_i_d)) {
db_query('DELETE FROM {files} WHERE fid = %d', $p_i_d->fid);
db_query('DELETE FROM {gallery_assist_translated} WHERE pid = %d', $p_i_d->pid);
db_query('DELETE FROM {gallery_assist_item} WHERE pid = %d', $p_i_d->pid);
}
}
if (file_exists($upload_dir . '/img/' . $node->newfile['name']['pictures' . $i])) {
file_delete($upload_dir . '/img/' . $node->newfile['name']['pictures' . $i]);
}
if (file_exists($upload_dir . '/thm/' . $node->newfile['name']['pictures' . $i])) {
file_delete($upload_dir . '/thm/' . $node->newfile['name']['pictures' . $i]);
}
if (file_exists($upload_dir . '/prev/' . $node->newfile['name']['pictures' . $i])) {
file_delete($upload_dir . '/prev/' . $node->newfile['name']['pictures' . $i]);
}
$replaced = TRUE;
}
$upl_file = file_save_upload('pictures' . $i, $validators, $upload_dir, $replace);
$upl_files[] = $upl_file;
if (isset($upl_file->filepath)) {
$a = explode('/', $upl_file->filepath);
$new_filename = end($a);
$gallery_assist_thumbnail = $upload_dir . '/img/' . $new_filename;
$upload_thm = $upload_dir . '/thm/' . $new_filename;
$upload_prev = $upload_dir . '/prev/' . $new_filename;
if (is_file($upl_file->filepath)) {
@chmod($upl_file->filepath, 0664);
}
$imageinfo = image_get_info($upl_file->filepath);
$my_dim_ref = $imageinfo['width'] > $imageinfo['height'] ? $imageinfo['width'] : $imageinfo['height'];
$img_direction = $imageinfo['width'] > $imageinfo['height'] ? 'h' : 'v';
if (80 < $my_dim_ref) {
@image_scale($upl_file->filepath, $gallery_assist_thumbnail, 80, 80);
}
else {
@copy($upl_file->filepath, $gallery_assist_thumbnail);
}
if (is_file($gallery_assist_thumbnail)) {
@chmod($gallery_assist_thumbnail, 0664);
}
// if ($conf['use_imagecache'] == 0) {
// $thmb_size = $conf['upload_thm'];
// $prev_size = $conf['upload_prev'] ? $conf['upload_prev'] : 550;
//
// if ($thmb_size < $my_dim_ref) {
// image_scale($upl_file->filepath, $upload_thm, $thmb_size, $thmb_size);
// }
// else {
// copy($upl_file->filepath, $upload_thm);
// }
// @chmod($upload_thm, 0664);
//
// if ($prev_size < $my_dim_ref) {
// image_scale($upl_file->filepath, $upload_prev, $prev_size, $prev_size);
// }
// else {
// copy($upl_file->filepath, $upload_prev);
// }
// @chmod($upload_prev, 0664);
//
// // Clear the cached filesize and refresh the image information.
// clearstatcache();
// }
// Set permanent status to the files table entries.
file_set_status($upl_file, 1);
$result = db_fetch_object(db_query("SELECT gid, gref FROM {gallery_assist} WHERE nid = %d", $node->nid));
$my_gref = $result->gref ? $result->gref : $result->gid;
$insert_item_data = array(
'nid' => $node->nid,
'ref' => $node->ref,
'gid' => $result->gid,
'gref' => $my_gref,
'sid' => $node->sid ? $node->sid : $node->gallconf[$node->type]['show_download_link'],
'uid' => $node->uid,
'fid' => $upl_file->fid,
'filename' => $new_filename,
'tpath' => $upload_thm,
'ppath' => $upload_prev,
'opath' => $upl_file->filepath,
'copyright' => $node->temp_copyright,
'weight' => $w,
'cover' => $cover,
);
drupal_write_record('gallery_assist_item', $insert_item_data);
// Get the pid from recent updated file.
$my_last_incerted = db_last_insert_id('gallery_assist_item', 'pid');
if ($cover == 1) {
$node->has_cover = $my_last_incerted;
}
// See how many language entries, and make the picture-entry for each language.
$just_translated = db_query("SELECT nid, lang FROM {gallery_assist} WHERE ref=%d", $node->ref);
while ($r = db_fetch_object($just_translated)) {
$my_ptitle = preg_replace('/\\_/', ' ', $my_ptitle);
$inset_translated_data = array(
'nid' => $r->nid,
'gid' => $result->gid,
'gref' => $my_gref,
'pid' => $my_last_incerted,
'lang' => $r->lang,
'ptitle' => $my_ptitle,
'palt' => $my_ptitle,
'pdescription' => '',
);
drupal_write_record('gallery_assist_translated', $inset_translated_data);
if (function_exists('pathauto_menu')) {
$new_item = new \stdClass();
$new_item->pid = $my_last_incerted;
$new_item->aid = 0;
$new_item->ptitle = $my_ptitle;
$new_item->old_ptitle = '';
$new_item->nid = $r->nid;
gallery_assist_rebuild_alias($new_item, $x);
}
}
if (module_exists('image_upload_gallery_assist') && $node->ga_multiupload == TRUE) {
drupal_set_message('The image ' . $my_ptitle . ' was uploaded sucessfull.');
return $upl_file;
}
else {
if ($replaced == FALSE) {
drupal_set_message(t('Add file: @file.', array(
'@file' => $my_ptitle,
)), 'status');
}
}
}
}
}
}
}
}
}
/**
* Implementation of hook_delete().
*/
function gallery_assist_delete(&$node) {
global $user;
if ($_POST['form_id'] == 'node_delete_confirm' && $_POST['confirm'] == 1) {
$delete = TRUE;
}
elseif ($_POST['form_id'] == 'node_admin_content' && $_POST['operation'] == 'delete' && $_POST['confirm'] == 1) {
$delete = TRUE;
}
else {
$delete = FALSE;
}
$count = db_result(db_query("SELECT count(*) FROM {gallery_assist} WHERE ref = %d", $node->ref));
if ($delete && !empty($node->ref) && $count == 1) {
if (gallery_assist_check_access($node, 'edit')) {
$settings = variable_get("gallery_assist_{$node->type}_data", array());
$galleries = db_result(db_query("SELECT count(*) FROM {gallery_assist} WHERE ref = %d", $node->ref));
if ($galleries == 1 and count($node->gallitems) > 0) {
foreach ($node->gallitems as $pid => $item) {
db_query("DELETE FROM {files} WHERE fid = %d", $item->fid);
db_query("DELETE FROM {gallery_assist_item} WHERE pid = %d", $pid);
db_query("DELETE FROM {gallery_assist_translated} WHERE pid = %d", $pid);
gallery_assist_delete_items($item);
}
gallery_assist_delete_directory(variable_get('gallery_assist_directory', file_directory_path() . '/gallery_assist') . '/' . $node->uid . '/' . $node->ganame);
// Send information to other modules when a image will be deleted.
$node_light = new \stdClass();
$node_light->nid = $node->nid;
$node_light->ref = $node->ref;
$node_light->nodetype = $node->type;
$count = db_result(db_query("SELECT count(*) FROM {gallery_assist} WHERE ref = %d", $node->ref));
if ($count == 1) {
foreach (module_implements('gallery_assist_api') as $name) {
$function = $name . '_gallery_assist_api';
$result = $function('delete', NULL, $node_light);
}
}
}
else {
db_query("DELETE FROM {gallery_assist_translated} WHERE gref = %d and lang = '%s'", $node->gref, $node->language);
}
db_query("DELETE FROM {gallery_assist} WHERE nid = %d", $node->nid);
}
}
}
/**
* Delete all gallery_assist items if the node will be deleted.
*
* @param $file
* A object containing the paths to the files should be deleted.
* @param $op
* A reserved variable for future options or conditions.
*
* @return TRUE if finish.
*/
function gallery_assist_delete_items($file, $op = FALSE) {
// Delete gallery_assist form thumbnails.
file_delete($file->thmb_path);
// Delete thumbnail item.
file_delete($file->tpath);
// Delete preview items.
file_delete($file->ppath);
// Delete original items.
file_delete($file->opath);
return TRUE;
}
/**
* Delete the prev and thumbnail dicectories if the node will be deleted.
*
* @param $dir
* A string containing the path to the directory should be deleted.
*
* @return TRUE if finish.
*/
function gallery_assist_delete_directory($dir) {
if (!file_exists($dir)) {
return TRUE;
}
if (!is_dir($dir) || is_link($dir)) {
return unlink($dir);
}
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') {
continue;
}
if (!gallery_assist_delete_directory($dir . "/" . $item)) {
chmod($dir . "/" . $item, 0777);
if (!gallery_assist_delete_directory($dir . "/" . $item)) {
return FALSE;
}
}
}
return rmdir($dir);
}
/**
* Make the gallery folder and the subfolders for each user with permissions.
* It is called from hook_load to create the user enviroment (user folder)
* It is called from the hook_save() by the first uploads (gallery
and components: thumbnails, preview, etc).
*
* @see gallery_assist_save().
*/
function gallery_assist_makedirs(&$node) {
// Build paths.
$my_files_folder = variable_get('gallery_assist_directory', FALSE);
$my_user_upload_folder = $my_files_folder . "/" . $node->uid;
$my_upload_folder = !empty($node->ref) ? $node->ref : $node->nid;
$my_gallery_upload_folder = $my_user_upload_folder . "/gallery_assist" . $my_upload_folder;
$gallery_assist_thumbnail = $my_gallery_upload_folder . "/img";
$my_gallery_thumbnails_folder = $my_gallery_upload_folder . "/thm";
$my_gallery_previews_folder = $my_gallery_upload_folder . "/prev";
// User folder.
file_check_directory($my_user_upload_folder, 1);
// Gallery upload folder.
file_check_directory($my_gallery_upload_folder, 1);
// Icons folder.
file_check_directory($gallery_assist_thumbnail, 1);
// Thumbnails folder.
file_check_directory($my_gallery_thumbnails_folder, 1);
// Preview folder.
file_check_directory($my_gallery_previews_folder, 1);
// Create the directories if needed.
// User gallery_assist folder.
// if (is_dir($my_user_upload_folder) && !is_dir($my_gallery_upload_folder)) {
// if (file_check_directory($my_gallery_upload_folder, 1));
// }
//
// // Gallery Assist form img folder.
// if (is_dir($my_user_upload_folder) && !is_dir($gallery_assist_thumbnail)) {
// if (file_check_directory($gallery_assist_thumbnail, 1));
// }
//
// // Gallery thumbnail folder.
// if (is_dir($my_gallery_upload_folder) && !is_dir($my_gallery_thumbnails_folder)) {
// if (file_check_directory($my_gallery_thumbnails_folder, 1));
// }
//
// // Gallery preview folder.
// if (is_dir($my_gallery_upload_folder) && !is_dir($my_gallery_previews_folder)) {
// if (file_check_directory($my_gallery_previews_folder, 1));
// }
}
/**
* Invoke a hook_myhooktest() operation in all modules.
*
* @param &$node
* A node object.
* @param $op
* A string containing the name of the nodeapi operation.
* @param $a3, $a4
* Arguments to pass on to the hook, after the $node and $op arguments.
* @return
* The returned value of the invoked hooks.
*/
function gallery_assist_invoke_myhooktest(&$node, $op, $a3 = NULL, $a4 = NULL) {
$return = array();
foreach (module_implements('myhooktest') as $name) {
$function = $name . '_myhooktest';
$result = $function($node, $op, $a3, $a4);
if (isset($result) && is_array($result)) {
$return = array_merge($return, $result);
}
elseif (isset($result)) {
$return[] = $result;
}
}
return $return;
}
/**
* Implementation of hook_nodeapi().
*/
function gallery_assist_nodeapi(&$node, $op, $teaser, $page) {
global $user, $base_url;
switch ($op) {
case 'load':
if ($node->type != 'gallery_assist' && variable_get('gallery_assist_' . $node->type, 0) == 1) {
$gallery = gallery_assist_load($node);
if (!isset($gallery->gid) && empty($gallery->ganame)) {
gallery_assist_insert($node);
$gallery = gallery_assist_load($node);
}
// Add Gallery Assist gallery data to the node object.
foreach ($gallery as $key => $addition) {
$node->{$key} = $addition;
}
}
break;
case 'update':
if ($node->type != 'gallery_assist' && variable_get('gallery_assist_' . $node->type, 0) == 1) {
$ui = variable_get('gallery_assist_ui_settings', array());
if (!isset($ui[$node->type]) || $ui[$node->type] == 0) {
gallery_assist_update($node);
}
}
break;
case 'view':
if (variable_get('gallery_assist_' . $node->type, 0) == 1 && count($node->gallconf) > 0) {
$display_extra = variable_get('gallery_assist_lightbox', 'none') == 'none' ? 'none' : 'lightbox';
if (gallery_assist_check_access($node) && gallery_assist_check_public_status($node, $user)) {
if ($teaser) {
if ($node->gallconf[$node->type]['hide_in_teaser'] != 1) {
$node->content['my_gallery_field'] = array(
'#value' => gallery_assist_include_display($node, 'teaser', $user, $display_extra),
'#weight' => $node->gallery_assist_weight,
);
}
}
if ($page) {
// Option to jump directly to the first image (cover) or a random image without to view the page.
if (count($node->gallitems) > 0 && $node->gallconf[$node->type]['gallery_call_type'] > 0) {
switch ($node->gallconf[$node->type]['gallery_call_type']) {
case 1:
$keys = array_keys($node->gallitems);
$image = array_shift($keys);
break;
case 2:
$keys = array_keys($node->gallitems);
shuffle($keys);
$image = array_shift($keys);
break;
}
drupal_goto('node/' . $node->nid . '/' . $image);
}
if ($node->gallconf[$node->type]['show_title'] && $node->gallconf[$node->type]['show_toggle']) {
if (empty($_GET['titles'])) {
$_GET['titles'] = $node->show_title == 1 ? 'on' : 'off';
}
$node->show_title = $_GET['titles'] == 'on' || empty($_GET['titles']) ? 1 : 0;
if ($node->show_title == 1) {
$toggle = t('Hide titles');
$toggle_value = 'off';
}
if ($node->show_title == 0) {
$toggle = t('Show titles');
$toggle_value = 'on';
}
if (count($node->gallitems) > 0 && $node->gallconf[$node->type]['show_toggle'] == 1 && $node->gallconf[$node->type]['show_layout'] == 'grid') {
$titles_toggle_link = l($toggle, 'node/' . $node->nid, array(
'query' => array(
'titles' => $toggle_value,
'page' => $_GET['page'],
),
));
if ($node->gallconf[$node->type]['position_toggle'] == 0) {
$position = $node->gallery_assist_weight - 1;
}
else {
$position = $node->gallery_assist_weight + 5;
}
$node->content['my_title_toggle'] = array(
'#value' => '<span>' . $titles_toggle_link . '<span>',
'#weight' => $position,
);
}
}
$node->content['my_gallery_field'] = array(
'#value' => gallery_assist_include_display($node, 'page', $user, $display_extra),
'#weight' => $node->gallery_assist_weight,
);
}
}
}
break;
case 'delete':
gallery_assist_delete($node);
// Send information to other modules when a image will be deleted.
$node_light = new \stdClass();
$node_light->nid = $node->nid;
$node_light->ref = $node->ref;
$node_light->nodetype = $node->type;
$count = db_result(db_query("SELECT count(*) FROM {gallery_assist} WHERE ref = %d", $node->ref));
if ($count == 1) {
foreach (module_implements('gallery_assist_api') as $name) {
$function = $name . '_gallery_assist_api';
$result = $function('delete', NULL, $node_light);
}
}
break;
}
}
/**
* Check the gallery public status.
*
* @param object $node
* @param object $user
* @return boolean
*/
function gallery_assist_check_public_status($node, $u, $op = 'default') {
if (empty($user)) {
global $user;
}
else {
$user = $u;
}
// switch ($op) {
// case 'default':
// $ga_public_status = $node->gallconf[$node->type]['ga_public_status'];
// break;
// case 'block':
// $ga_public_status = $node->ga_public_status;
// break;
// }
switch ($node->ga_public_status) {
case 'ur':
return TRUE;
case 2:
return TRUE;
case 1:
if ($user->uid == 1 || $node->uid == $user->uid) {
return TRUE;
}
else {
return FALSE;
}
case 0:
if ($user->uid != 0) {
return TRUE;
}
else {
return FALSE;
}
}
}
/**
* Check if user have edit or access permitions and if positiv check the gallery public status.
*
* @param object $node
* @param object $user
* @param string $op
* @return boolean
*/
function _gallery_assist_check_access($node, $account, $op = 'view') {
$access = gallery_assist_access($op, $node, $account);
return $access;
switch ($op) {
case 'edit':
if ($user->uid == $node->uid && (user_access('edit own gallery_assist content', $user) || user_access('edit own gallery_assist_' . $node->type . ' content', $user))) {
return TRUE;
}
elseif (user_access('edit any gallery_assist content', $user) || user_access('edit any gallery_assist_' . $node->type . ' content', $user)) {
return TRUE;
}
else {
return FALSE;
}
case 'view':
if (user_access('view gallery_assist content', $user) || user_access('view gallery_assist_' . $node->type . ' content', $user)) {
return gallery_assist_check_public_status($node, $user) == 1 ? TRUE : FALSE;
}
else {
return FALSE;
}
}
}
/**
* Display gallery assist container.
*
* @param $node
* A object containing the node data.
* @param $op
* A string containing the display option (teaser|page).
* @param $owner
* A integer containing the UID.
* @param $display_extra
* A string containing the display option to include the right display inc files. none for default, lightbox if a lightbox is needed.
*/
function gallery_assist_include_display(&$node, $op = '', $owner = '', $display_extra = 'none') {
if (empty($node->gallconf[$node->type]['show_layout'])) {
$node->gallconf[$node->type]['show_layout'] = 'grid';
}
//$display_extra = 'third_party';
switch ($display_extra) {
case 'none':
switch ($node->gallconf[$node->type]['show_layout']) {
case 'grid':
module_load_include('inc', 'gallery_assist', 'gallery_assist_display');
return gallery_assist_display($node, $op, $owner);
break;
case 'list':
module_load_include('inc', 'gallery_assist', 'gallery_assist_list_display');
return gallery_assist_display_list($node, $op, $owner);
break;
}
break;
case 'lightbox':
switch ($node->gallconf[$node->type]['show_layout']) {
case 'grid':
module_load_include('inc', 'gallery_assist_lightboxes', 'gallery_assist_lightboxes_display');
return gallery_assist_display($node, $op, $owner);
break;
case 'list':
module_load_include('inc', 'gallery_assist_lightboxes', 'gallery_assist_lightboxes_list_display');
return gallery_assist_display_list($node, $op, $owner);
break;
}
break;
case 'third_party':
module_load_include('inc', 'gallery_assist', 'third_party/flow_jq_tools');
//return _gallery_assist_jqft_display($node, $op, $owner);
$test = _gallery_assist_jqft_display($node, $op, $owner);
break;
}
}
/**
* Allow to use jquery effects on the image view such as flash, slideshow, zoom viewer, galleria.
*
* @param $node
* A object containing the node data.
* @param $pid
* A integer contains the PID (picture ID) should be displayed.
*/
function gallery_assist_display_item($node, $pid) {
if (is_numeric($pid) || $pid == 'cover') {
if (!is_numeric($pid)) {
if ($pid == 'lightbox2') {
return;
}
elseif ($pid == 'cover') {
$pid = db_result(db_query("SELECT pid FROM {gallery_assist_item} WHERE gref = %d AND cover = 1", $node->gref));
}
else {
$pid = db_result(db_query("SELECT p.pid FROM {gallery_assist_item} p JOIN {gallery_assist_translated} t ON p.pid = t.pid WHERE p.gref = %d AND t.ptitle = '%s'", $node->gref, $pid));
}
}
// Check if the image exists.
if (!isset($node->gallitems[$pid])) {
drupal_set_message(t('The requested image not exist or is not longer published.'));
drupal_goto('node/' . $node->nid);
}
global $user;
$data = variable_get('gallery_assist_' . $node->type . '_data', FALSE);
//$data['item_display_option'] = 'mbImgNav';
$item_effect = $node->gallconf[$node->type]['item_effect'] ? $node->gallconf[$node->type]['item_effect'] : 'default';
switch ($item_effect) {
case 'default':
$output = gallery_assist_display_item_default($node, $pid, $data);
break;
case 'cicle':
if (module_exists('gallery_assist_item')) {
module_load_include('inc', 'gallery_assist_item', 'gallery_assist_display_item_cicle');
$output = gallery_assist_display_item_cicle($node, $pid, $data);
}
break;
case 'innerfade':
if (module_exists('gallery_assist_item')) {
module_load_include('inc', 'gallery_assist_item', 'gallery_assist_display_item_cicle');
$output = gallery_assist_display_item_innerfade($node, $pid, $data);
}
break;
case 'dewslider':
if (module_exists('gallery_assist_item')) {
module_load_include('inc', 'gallery_assist_item', 'gallery_assist_display_item_cicle');
$output = gallery_assist_display_item_dewslider($node, $pid, $data);
}
break;
case 'jcarousellite':
if (module_exists('gallery_assist_item')) {
module_load_include('inc', 'gallery_assist_item', 'gallery_assist_display_item_cicle');
$output = gallery_assist_display_item_jcarousellite($node, $pid, $data);
}
break;
case 'galleria':
if (module_exists('gallery_assist_item')) {
module_load_include('inc', 'gallery_assist_item', 'gallery_assist_display_item_cicle');
$output = gallery_assist_display_item_galleria($node, $pid, $data);
}
break;
case 'mbgallery':
if (module_exists('gallery_assist_item')) {
module_load_include('inc', 'gallery_assist_item', 'gallery_assist_display_item_cicle');
$output = gallery_assist_display_item_mbgallery($node, $pid, $data);
}
break;
case 'mbImgNav':
if (module_exists('gallery_assist_item')) {
module_load_include('inc', 'gallery_assist_item', 'gallery_assist_display_item_cicle');
$output = gallery_assist_display_item_mbImgNav($node, $pid, $data);
}
break;
}
return $output;
}
else {
return FALSE;
}
}
/**
* Build the output to display each gallery image.
* Call the own pager and the theme.
*/
function gallery_assist_display_item_default($node, $pid, $global_node_type_settings = array()) {
global $user, $base_url;
if (gallery_assist_check_access($node)) {
if (gallery_assist_check_public_status($node, $user)) {
$item = new \stdClass();
$node->galltemp['active_item'] = $pid;
$node->galltemp['class_active'] = '';
$node->galltemp['path'] = '';
$breadcrumb = drupal_get_breadcrumb();
$breadcrumb[] = l($node->title, 'node/' . $node->nid);
$breadcrumb[] = $node->gallitems[$pid]->ptitle;
drupal_set_breadcrumb($breadcrumb);
$node->file_created = db_result(db_query("SELECT timestamp FROM {files} WHERE fid=%d", $node->gallitems[$pid]->fid));
$node->dateformate = t('D, m/d/Y - h:i');
$item->nid = $node->nid;
$item->nodetype = $node->type;
$item->title = $node->title;
$theme_settings = theme_get_settings();
// $item->submitted = $theme_settings["toggle_node_info_{$node->type}_item"] ? theme('gallery_assist_item_submitted', $node) : '';
$node->created = $node->file_created;
$item->submitted = $theme_settings["toggle_node_info_{$node->type}_item"] ? theme('node_submitted', $node) : '';
$conf = $node->gallconf[$node->type];
$item->preview_size = $node->gallconf[$node->type]['preview_size'];
if (variable_get('gallery_assist_imagecache_uninstalled', FALSE) == 1 && !file_exists(file_create_path($node->gallitems[$pid]->ppath)) && file_exists($node->gallitems[$pid]->opath)) {
// drupal_set_message($additions->gallitems[$item->pid]->ptitle .' wurde nicht gefunden', 'warning');
$h_imageinfo = image_get_info($node->gallitems[$pid]->opath);
$my_dim_ref = $h_imageinfo['width'] > $h_imageinfo['height'] ? $h_imageinfo['width'] : $h_imageinfo['height'];
$item->h_prev_size = $h_prev_size = $node->gallconf[$node->type]['upload_prev'];
if ($h_prev_size < $my_dim_ref) {
@image_scale($node->gallitems[$pid]->opath, $node->gallitems[$pid]->ppath, $h_prev_size, $h_prev_size);
}
else {
@copy($node->gallitems[$pid]->opath, $node->gallitems[$pid]->ppath);
}
@chmod($node->gallitems[$pid]->tpath, 0664);
// drupal_set_message('The preview image from '. $node->gallitems[$pid]->ptitle .' was recreated sucessfull.');
}
//-------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------//
// We use the if to avoid division by zero if the image path is wrong
// $img = image_get_info($node->gallitems[$pid]->ppath);
// if (count($img) && !empty($img['width'])) {
// $size_param = $img['width'] >= $img['height'] ? 'width' : 'height';
// $contraer = $size_param == 'width' ? 'max-height:'. $img['height'] .'px' : 'max-width:'. $img['width'] .'px';
// $size_param_ie6 = $img['width'] >= $img['height'] ? '_width' : '_height';
// $size_param_ie7 = $img['width'] >= $img['height'] ? '>width' : '>height';
// $size_param_max = $img['width'] >= $img['height'] ? 'max-width' : 'max-height';
// if ($img[$size_param] < $item->preview_size) {
// $item->preview_size = $img[$size_param];
// }
// $style_str = array(
// $contraer,
// $size_param .': 100%',
// $size_param_max .':'. $item->preview_size .'px',
// $size_param_ie6 .':'. $item->preview_size .'px',
// $size_param_ie7 .':'. $item->preview_size .'px',
// );
// $size_parameter = implode(';', $style_str);
// }
// else {
// $img = image_get_info($node->gallitems[$pid]->opath);
// $size_param = $img['width'] >= $img['height'] ? 'width' : 'height';
// $size_param_ie6 = $img['width'] >= $img['height'] ? '_width' : '_height';
// $size_param_ie7 = $img['width'] >= $img['height'] ? '>width' : '>height';
// $size_param_max = $img['width'] >= $img['height'] ? 'max-width' : 'max-height';
// if ($img[$size_param] < $item->preview_size) {
// $item->preview_size = $img[$size_param];
// }
// $style_str = array(
// $contraer,
// $size_param .': 100%',
// $size_param_max .':'. $item->preview_size .'px',
// $size_param_ie6 .':'. $item->preview_size .'px',
// $size_param_ie7 .':'. $item->preview_size .'px',
// );
// $size_parameter = implode(';', $style_str);
// }
//-------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------//
if (file_exists($node->gallitems[$pid]->ppath)) {
$info = image_get_info($node->gallitems[$pid]->ppath);
$img['width'] = $info['width'];
$img['height'] = $info['height'];
}
else {
$info = image_get_info($node->gallitems[$pid]->opath);
$info = gallery_assist_image_prev_more_info($info, $conf);
$img['width'] = $info['new_width'];
$img['height'] = $info['new_height'];
}
$node->pid = $pid;
$links = gallery_assist_item_pager($node);
if (function_exists('imagecache_preset') && variable_get('gallery_assist_use_imagecache', 0) == 1) {
$item->img = theme('imagecache', $node->gallconf[$node->type]['prev_presetname'], $node->gallitems[$pid]->opath, $node->gallitems[$pid]->palt, $node->gallitems[$pid]->ptitle, array(), TRUE);
$item->img = l($item->img, "node/{$node->nid}/{$links['next']}", array(
'html' => TRUE,
'fragment' => 'ga-item-top',
'attributes' => array(
'fragment' => 'ga-item-top',
),
));
}
else {
$prev_attr = array(
'id' => 'prev-img-box',
'style' => 'width:' . $img['width'] . 'px;height:' . $img['height'] . 'px;',
);
$item->img = '<div ' . drupal_attributes($prev_attr) . '>' . theme('image', file_create_url($node->gallitems[$pid]->ppath), $node->gallitems[$pid]->palt, $node->gallitems[$pid]->ptitle, array(
'style' => isset($size_parameter) ? $size_parameter : '',
), FALSE) . '</div>';
$item->img = l($item->img, "node/{$node->nid}/{$links['next']}", array(
'html' => TRUE,
'fragment' => 'ga-item-top',
'attributes' => array(
'fragment' => 'ga-item-top',
),
));
$prev = image_get_info($node->gallitems[$pid]->ppath);
}
$item->ppath = $node->gallitems[$pid]->ppath;
$item->boxes_width = 'width:' . $item->preview_size . 'px;max-width:' . $item->preview_size . 'px;_width:' . $item->preview_size . 'px;>width:' . $item->preview_size . 'px;';
$item->ptitle = drupal_set_title(check_plain($node->gallitems[$pid]->ptitle));
$item->pdescription = check_markup($node->gallitems[$pid]->pdescription, $node->gallitems[$pid]->format);
$build_copyright_string = _filter_html(_filter_url($node->gallitems[$pid]->copyright, 1), 1);
$item->copyright = $build_copyright_string;
if ($conf['pager_position'] == 'top') {
$item->top = 1;
}
elseif ($conf['pager_position'] == 'bottom') {
$item->top = 0;
}
else {
$item->top = 3;
}
$node->pid = $pid;
$node_light = new \stdClass();
$node_light->nodetype = $node->type;
$node_light->pager_style = $node->gallconf[$node->type]['xx'];
$extras['pager_position'] = $conf['pager_position'];
$item->pager = count($node->gallitems) > 1 ? theme('gallery_assist_pager', $node_light, $links['all'], $extras) : '';
$link_helper = $node->type == 'gallery_assist' ? '' : '_' . $node->type;
$link = l('edit', 'node/ga_edit_one' . $link_helper . '/' . $item->nid . '/' . $pid);
$adm_link = '<div id="image-box-links"> [ ' . $link . ' ] </div>' . "\n";
$item->adm_link = $user->uid == $node->gallitems[$pid]->uid ? $adm_link : '';
if ($global_node_type_settings['show_download_link'] == 0) {
$item->allow_download = 0;
}
else {
if ($node->gallitems[$pid]->sid != $node->gallconf[$node->type]['show_download_link']) {
$item->allow_download = $node->gallitems[$pid]->sid;
}
else {
$item->allow_download = $node->gallconf[$node->type]['show_download_link'];
}
$item->download_path = file_create_url($node->gallitems[$pid]->opath);
}
$links_graf = $node->gallconf[$node->type]['graphlinks'];
$separator = isset($links_graf) && $links_graf ? '' : ' - ';
$item->link = array();
if ($conf['show_backlink'] == 1) {
$item->link['back'] = $links_graf ? gallery_assist_build_div(l('« ' . t('Back to the gallery'), 'node/' . $node->nid, array(
'attributes' => array(
'title' => t('Back to the gallery'),
'class' => 'ga-back-link',
),
)), 'back-link') : l('« ' . t('Back to the gallery'), 'node/' . $node->nid, array(
'attributes' => array(
'title' => t('Back to the gallery'),
'class' => 'ga-back-link',
),
));
}
if ($conf['gallery_call_type'] > 0) {
$item->link['back'] = gallery_assist_build_div(l('« ' . t('Edit the gallery'), 'node/' . $node->nid . '/edit', array(
'attributes' => array(
'title' => t('Edit the gallery'),
'class' => 'ga-node-edit-link',
),
)), 'node-edit-link');
}
$edit_link_query = array();
if (isset($_GET['page'])) {
$edit_link_query['page'] = $_GET['page'];
}
if (isset($_GET['titles'])) {
$edit_link_query['titles'] = $_GET['titles'];
}
// if (gallery_assist_check_access($node, 'edit')) {
// $item->link['edit'] = $links_graf ? gallery_assist_build_div(l(t('Edit this item'), 'node/ga_edit_one'. $link_helper .'/'. $node->nid .'/'. $pid, array('attributes' => array('title' => t('Edit this item'), 'class' => 'ga-edit-item-link'))), 'edit-item-link') : l(t('Edit this item'), 'node/ga_edit_one'. $link_helper .'/'. $node->nid .'/'. $pid, array('query' => $edit_link_query, 'attributes' => array('title' => t('Edit this item'), 'class' => 'ga-edit-item-link')));
// }
if ($links_graf) {
$item->links = !empty($item->link['back']) ? $item->link['back'] : '';
$item->links .= !empty($item->link['edit']) ? $item->link['edit'] : '';
}
else {
$values = array_values($item->link);
$item->links = gallery_assist_build_div(implode(' - ', $values), 'nav-links');
}
if ($node->gallconf[$node->type]['gap_align'] !== 'node') {
$item->extra_styles = array();
switch ($conf['gap_align']) {
case 'left':
$item->extra_styles = 'margin-right:auto;';
$item->img_extra_styles = 'text-align:left;';
break;
case 'center':
$item->extra_styles = 'margin-left:auto;margin-right:auto;';
$item->img_extra_styles = 'text-align:center;';
break;
case 'right':
$item->extra_styles = 'margin-left:auto;';
$item->img_extra_styles = 'text-align:right;';
break;
}
}
//gallery_assist_add_css('gallery_assist');
$results = array();
$results[] = array(
'#value' => theme('gallery_assist_item', $item),
'#weight' => -20,
);
$output = drupal_render($preview_display);
$node_light = new stdClass();
$node_light->uid = $node->uid;
$node_light->nodetype = $item->nodetype;
$node_light->nid = $node->nid;
$node_light->ref = $node->ref;
$node_light->gid = $node->gid;
$node_light->gref = $node->gref;
$node_light->pid = $pid;
$node_light->preview_size = $item->preview_size;
$node_light->container_width = $item->boxes_width;
$node_light->extra_styles = $item->extra_styles;
$node_light->opath = $node->gallitems[$pid]->opath;
$node_light->info = $img;
foreach (module_implements('gallery_assist_api') as $name) {
$function = $name . '_gallery_assist_api';
$node_light->node_settings = unserialize($node->gallconf[$node->type]['modules'][$name]['data']);
$result = $function('view', $pid, $node_light);
if (is_string($result)) {
$results[$name] = array(
'#value' => $result,
'#weight' => 2000,
);
}
elseif (is_array($result) && count($result) > 0) {
$results[$name] = $result;
if (isset($result['#weight'])) {
$results[$name]['#weight'] = $result['#weight'];
}
}
}
$output .= drupal_render($results);
}
else {
drupal_goto($base_url);
}
return $output;
}
}
function gallery_assist_build_div($link, $class = 'default-container') {
return '<div class="clear-block ga-' . $class . '">' . $link . '</div>';
}
/**
* Theme the output from the submited line. Multilingual.
*
* @ingroup themeable
*/
function theme_gallery_assist_item_submitted($node) {
return t('Submitted by !username on @datetime', array(
'!username' => theme('username', $node),
'@datetime' => format_date($node->file_created, 'custom', t('D, m/d/Y - h:i')),
));
}
/**
* Theme the output of a singel item.
*
* @ingroup themeable
*/
function theme_gallery_assist_item($item = array()) {
$output .= ' <div class="clear-block gallery-assist-item-container">' . "\n";
$output .= ' <div id="node-' . $item->nid . '" class="node">' . "\n";
if ($item->submitted) {
$output .= ' <span class="submitted">' . $item->submitted . '</span>' . "\n";
}
$output .= ' <div class="clear-block">' . $item->links . '</div>' . "\n";
$output .= ' <div class="content clear-block">' . "\n";
if ($item->top == 1 || $item->top == 3) {
$output .= ' <div id="ga-pager" class="' . $item->nodetype . ' ga-pager clear-block">' . $item->pager . '</div>' . "\n";
}
$output .= ' <div id="ga-image-display" class="' . $item->nodetype . ' ga-image-display" style="' . $item->size_parameters . ';' . $item->extra_styles . $item->img_extra_styles . '">' . "\n";
$output .= $_GET['links'] == 'on' ? $item->adm_link : '';
$output .= $item->img;
$output .= '</div>';
if ($item->top == 0 || $item->top == 3) {
$output .= ' <div id="ga-pager" class="' . $item->nodetype . ' ga-pager clear-block">' . $item->pager . '</div>' . "\n";
}
$output .= empty($item->copyright) ? '' : ' <div id="gallery-item-copyright" class="' . $item->nodetype . ' gallery-item-copyright" style="' . $item->boxes_width . ';' . $item->extra_styles . '">© ' . $item->copyright . '</div>' . "\n";
if ($item->ptitle) {
$output .= ' <div id="gallery-item-caption-title" class="' . $item->nodetype . ' gallery-item-caption-title" style="' . $item->boxes_width . ';' . $item->extra_styles . '">' . $item->ptitle . '</div>' . "\n";
}
if ($item->pdescription) {
$output .= ' <div id="gallery-item-caption-text" class="' . $item->nodetype . ' gallery-item-caption-text" style="' . $item->boxes_width . ';' . $item->extra_styles . '">' . $item->pdescription . '</div>' . "\n";
}
if ($item->allow_download == 1) {
$output .= ' <div id="gallery-item-download-link" class="' . $item->nodetype . ' gallery-item-download-link" style="' . $item->boxes_width . ';' . $item->extra_styles . '"><a href="' . $item->download_path . '">Download</a></div>' . "\n";
}
$output .= ' </div>' . "\n";
$output .= ' </div>' . "\n";
$output .= ' </div>' . "\n";
return $output;
}
/**
* Build the pager for this module.
*
* @param $node
* A object containing the node data.
* @param $extras
* A array reserved to send to this module options or conditions.
*/
function gallery_assist_item_pager($node, $extras = NULL) {
$conf = $node->gallconf[$node->type];
$my_total = count($node->gallitems);
if (count($node->gallitems) <= 1) {
return;
}
$data = array();
$i = 0;
foreach ($node->gallitems as $k => $v) {
++$i;
$data[$i] = $node->gallitems[$k];
$node->gallitems[$k]->counter = $i;
}
$my_page = isset($node->gallitems[$node->pid]->counter) ? $node->gallitems[$node->pid]->counter : 1;
$max_vis = $conf['pager_visibles'] < $my_total ? $conf['pager_visibles'] : $my_total + 2;
$my_quantity = $my_total > $my_quantity ? $max_vis : $my_total;
$my_short = $my_total > $my_quantity - 2 ? 1 : 0;
$my_odd = $my_quantity & 1;
$my_n = $my_odd == 1 ? 0 : 1;
$my_middle = ceil($my_quantity / 2);
$my_attributes = array(
'class' => $node->type . ' pager',
);
if ($conf['gap_align'] !== 'node') {
switch ($conf['gap_align']) {
case 'left':
$my_attributes['style'] = $conf['pager_align'] == 'left' ? 'text-align:left;' : 'text-align:' . $conf['pager_align'];
break;
case 'center':
$my_attributes['style'] = $conf['pager_align'] == 'center' ? 'text-align:center;' : 'text-align:' . $conf['pager_align'];
break;
case 'right':
$my_attributes['style'] = $conf['pager_align'] == 'right' ? 'text-align:right;' : 'text-align:' . $conf['pager_align'];
break;
}
}
$my_active_opts = array(
'attributes' => array(
'class' => $node->type . ' active',
),
'html' => TRUE,
);
$theme = variable_get('theme_default', FALSE);
$my_pager_layout = $conf['pager_layout'];
$my_grafic_previous_path = file_exists(drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/previous.png') ? drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/previous.png' : drupal_get_path('module', 'gallery_assist') . '/ga_pager/default/previous.png';
$my_grafic_previous = theme('image', $my_grafic_previous_path, '', t('go to the previous'));
$my_grafic_next_path = file_exists(drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/next.png') ? drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/next.png' : drupal_get_path('module', 'gallery_assist') . '/ga_pager/default/next.png';
$my_grafic_next = theme('image', $my_grafic_next_path, '', t('go to the next'));
if ($conf['pager_format'] == 0) {
$my_grafic_first_path = file_exists(drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/first.png') ? drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/first.png' : drupal_get_path('module', 'gallery_assist') . '/ga_pager/default/first.png';
$my_grafic_first = theme('image', $my_grafic_first_path, '', t('go to the first'));
$my_grafic_hellip_path = file_exists(drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/hellip.png') ? drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/hellip.png' : drupal_get_path('module', 'gallery_assist') . '/ga_pager/default/hellip.png';
$my_grafic_hellip = theme('image', $my_grafic_hellip_path);
$my_grafic_last_path = file_exists(drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/last.png') ? drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/last.png' : drupal_get_path('module', 'gallery_assist') . '/ga_pager/default/last.png';
$my_grafic_last = theme('image', $my_grafic_last_path, '', t('go to the last'));
$my_first = $conf['pager_symbol'] == 0 ? t('« first') : $my_grafic_first;
$my_last = $conf['pager_symbol'] == 0 ? t('last »') : $my_grafic_last;
$my_hellip = $conf['pager_symbol'] == 0 ? '…' : $my_grafic_hellip;
}
$my_previous = $conf['pager_symbol'] == 0 || $my_quantity == 0 ? t('‹ previous') : $my_grafic_previous;
$my_next = $conf['pager_symbol'] == 0 || $my_quantity == 0 ? t('next ›') : $my_grafic_next;
$link_helper = $node->type == 'gallery_assist' ? '' : '_' . $node->type;
$my_pager_paths = $extras == 'edit-one' ? 'node/ga_edit_one' . $link_helper . '/' . $node->nid . '/' : 'node/' . $node->nid . '/';
$get_values = array();
$get_values = $_GET;
unset($get_values['q']);
$my_active_opts['query'] = $get_values;
// $link = l('[edit]', 'node/ga_edit_one/'. $item->nid .'/'. $item->pid, array('query' => $get_values));
if ($my_quantity > 0) {
$before[] = array(
'class' => $node->type . ' pager-first',
'data' => $my_page > 1 ? l($my_first, $my_pager_paths . $data[1]->pid, $my_active_opts) : $my_first,
);
}
$before[] = array(
'class' => $node->type . ' pager-previous',
'data' => $my_page == 1 ? l($my_previous, $my_pager_paths . $data[$my_total]->pid, $my_active_opts) : l($my_previous, $my_pager_paths . $data[$my_page - 1]->pid, $my_active_opts),
);
if ($my_quantity > 0 && $conf['pager_format'] == 0) {
$before[] = array(
'class' => $node->type . ' pager-ellipsis',
'data' => $my_short == 1 && $my_page > $my_middle ? $my_hellip : ' ',
);
}
$c = 1;
$links = array();
foreach ($data as $k => $v) {
if ($c == $my_page) {
$my_clss = 'pager-current';
if (function_exists('imagecache_preset') && is_numeric($conf['pager_presetid'])) {
$my_mini = theme('imagecache', $conf['pager_presetname'], $data[$c]->opath, '', $c . ' / ' . $my_total, array(
'class' => $node->type . ' pager-thumbnail ic-on',
), FALSE);
}
else {
$my_mini = theme('image', file_create_url($data[$c]->thmb_path), '', $c . ' / ' . $my_total, array(
'height' => $conf['pager_t_active_height'],
'class' => $node->type . ' gallery-assist-thumbnail',
), FALSE);
}
$my_pager_layout_def = $extras == 'edit-one' ? 1 : $conf['pager_symbol'];
$my_data = $my_pager_layout_def == 1 ? $my_mini : $c;
}
else {
$my_clss = 'pager-item';
if (function_exists('imagecache_preset') && is_numeric($conf['pager_presetid'])) {
$my_mini = theme('imagecache', $conf['pager_presetname'], $data[$c]->opath, '', $c . ' / ' . $my_total, array(
'class' => $node->type . ' pager-thumbnail ic-off',
), FALSE);
}
else {
$my_mini = theme('image', file_create_url($data[$c]->thmb_path), '', $c . ' / ' . $my_total, array(
'height' => $conf['pager_t_height'],
'id' => 'pager-icon',
'class' => $node->type . ' gallery-assist-thumbnail',
), FALSE);
}
$my_pager_layout_def = $extras == 'edit-one' ? 1 : $conf['pager_symbol'];
$my_symbol = $my_pager_layout_def == 1 ? $my_mini : $c;
$my_data = l($my_symbol, $my_pager_paths . $data[$c]->pid, $my_active_opts);
}
$links[] = array(
'class' => $node->type . ' ' . $my_clss,
'data' => $my_data,
);
$c++;
}
$mylinks = $links;
if ($my_short == 1 && $my_total > $my_quantity) {
if ($my_page > $my_total - $my_quantity) {
if ($my_page + $my_middle - $my_odd < $my_total) {
$mysmall = array_slice($links, $my_page - $my_middle, $my_quantity, TRUE);
}
else {
$mysmall = array_slice($links, $my_total - $my_quantity, $my_quantity, TRUE);
}
}
elseif ($my_page <= $my_quantity) {
if ($my_page >= $my_middle) {
$mysmall = array_slice($links, $my_page - $my_middle, $my_quantity, TRUE);
}
else {
$mysmall = array_slice($links, 0, $my_quantity, TRUE);
}
}
else {
$mysmall = array_slice($links, $my_page - $my_middle, $my_middle + $my_middle - $my_odd, TRUE);
}
}
else {
$mysmall = array(
'',
);
}
$my_after_data = $my_short == 1 && $my_page + $my_middle + $my_n <= $my_total ? $my_hellip : ' ';
if ($my_quantity > 0 && $conf['pager_format'] == 0) {
$after[] = array(
'class' => $node->type . ' pager-ellipsis',
'data' => $my_after_data,
);
}
$next_image = $my_page == $my_total ? $data[1]->pid : $data[$my_page + 1]->pid;
$after[] = array(
'class' => $node->type . ' pager-next',
'data' => $my_page == $my_total ? l($my_next, $my_pager_paths . $data[1]->pid, $my_active_opts) : l($my_next, $my_pager_paths . $data[$my_page + 1]->pid, $my_active_opts),
);
if ($my_quantity > 0 && $conf['pager_format'] == 0) {
$after[] = array(
'class' => $node->type . ' pager-last',
'data' => $my_page == count($node->gallitems) ? $my_last : l($my_last, $my_pager_paths . $data[$my_total]->pid, $my_active_opts),
);
}
$mylinks = $my_short == 1 ? $mysmall : $links;
$links = array_merge($before, $mylinks, $after);
// $output = theme('item_list', $links, NULL, 'ul', $my_attributes);
$output = array(
'all' => theme('item_list', $links, NULL, 'ul', $my_attributes),
'next' => $next_image,
);
return $output;
}
/**
* Theme the output from the gallery pager.
*
* @ingroup themeable
*/
function theme_gallery_assist_pager($node_light, $links, $extras = array()) {
$output = '<div id="ga-pager-box" class="pager-' . $extras['pager_position'] . ' clear-block next-line" style="' . $extras['pager_style'] . '">';
$output .= $links;
$output .= '</div>';
return $output;
}
/**
* Render the image item acording needed.
*
* @param $item
* An associative array containing the gallery item data.
* @param $conf
* An associative array the gallery settings data.
*/
function gallery_assist_prepare_thms($item = array(), $conf = array()) {
$title = '';
if ($conf['opt'] == 'teaset' && $conf['t_thm_link_format'] == 'none') {
$title .= "Click the title or the Read more to see all images of this gallery | image: ";
}
$title .= $item->ptitle;
$title .= $item->copyright ? ' | © ' . $item->copyright : '';
if (function_exists('imagecache_preset') && $conf['use_imagecache'] == 1) {
$my_img = theme('imagecache', $conf['thm_presetname'], $item->opath, $item->palt, $title, $item->my_img_attr, FALSE);
}
else {
$my_img = theme('image', file_create_url($item->tpath), $item->palt, $title, $item->my_img_attr, FALSE);
}
return $my_img;
}
/**
* Render the image item acording needed.
*
* @param $item
* An associative array containing the gallery item data.
* @param $conf
* An associative array the gallery settings data.
*/
function gallery_assist_prepare_prev($item = array(), $conf = array()) {
$title = $item->ptitle;
$title .= $item->copyright ? ' | © ' . $item->copyright : '';
if (function_exists('imagecache_preset') && $conf['use_imagecache'] == 1) {
$my_img = theme('imagecache', $conf['prev_presetname'], $item->opath, $item->palt, $title, $item->my_img_attr, FALSE);
}
else {
$my_img = theme('image', file_create_url($item->ppath), $item->palt, $title, $item->my_img_attr, FALSE);
}
return $my_img;
}
/**
* Implementation of hook_block().
*/
function gallery_assist_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$block[0] = array(
'info' => gallery_assist_block_helper(0),
'title' => gallery_assist_block_helper(0),
'visibility' => 1,
);
$block[1] = array(
'info' => gallery_assist_block_helper(1),
'title' => gallery_assist_block_helper(1),
'visibility' => 1,
);
$block[2] = array(
'info' => gallery_assist_block_helper(2),
'title' => gallery_assist_block_helper(2),
'visibility' => 1,
);
return $block;
case 'configure':
$form = array();
if (module_exists('i18n')) {
$form = _gallery_assist_block_lgsettings_form($delta);
}
$form = _gallery_assist_block_settings_form($delta);
return $form;
case 'save':
$post_data = $_POST;
_gallery_assist_block_settings_form_submit($delta, $post_data);
break;
case 'view':
default:
switch ($delta) {
case 0:
// $block = array(
// 'subject' => gallery_assist_block_helper(0),
// 'content' => _gallery_assist_block_display(0)
// );
$block = _gallery_assist_block_display(0);
break;
case 1:
$block = array(
'subject' => gallery_assist_block_helper(0),
'content' => _gallery_assist_block_display_1(1),
);
break;
case 2:
$block = array(
'subject' => gallery_assist_block_helper(0),
'content' => _gallery_assist_block_display_2(2),
);
break;
}
return $block;
}
}
/**
* Display the GA-Block Galleries (0).
*/
function _gallery_assist_block_display($delta) {
global $user, $language;
// Avoid User-ID 0.
//$u = 1;
if (arg(0) == 'node' && is_numeric(arg(1)) || arg(0) == 'node' && is_numeric(arg(1)) && is_numeric(arg(2))) {
$u = db_result(db_query("SELECT uid FROM {gallery_assist} WHERE ref = %d", arg(1)));
}
if (arg(0) == 'user' && is_numeric(arg(1))) {
$u = arg(1);
}
$myLink = array();
$attr = array();
//$u = 1;
// Get settings.
$data = variable_get('gallery_assist_block_data', FALSE);
$data[$delta]['thumbnail_size'] = $data[$delta]['item_size'];
$cover = $data[$delta]['bformat'] == 'pic' ? "AND p.cover = 1" : '';
$order = $data[$delta]['bformat'] == 'lnk' ? 'ORDER BY n.created DESC' : '';
$i18_n = variable_get('i18n_selection_mode', FALSE);
$i18_n = variable_get('i18n_selection_mode', FALSE);
if (module_exists('i18n') && $i18_n == 'strict') {
$tlang = "AND g.lang = '%s'";
$arguments = array(
'pic' => array(
$u,
$language->language,
$data[$delta]['visibles'],
),
'lnk' => array(
$u,
$language->language,
$data[$delta]['visibles'],
),
);
}
else {
$tlang = '';
$arguments = array(
'pic' => array(
$u,
$data[$delta]['visibles'],
),
'lnk' => array(
$u,
$data[$delta]['visibles'],
),
);
}
$q['pic'] = "SELECT n.nid, n.title, n.type, g.data, p.tpath, p.opath\n FROM {node} n\n JOIN {gallery_assist} g ON g.nid = n.nid\n JOIN {gallery_assist_item} p on p.gref = g.gref\n WHERE\n g.show_in_homepage_block = 1\n AND n.uid = %d\n {$tlang}\n AND p.cover = 1\n ORDER BY n.created DESC\n LIMIT %d";
$q['lnk'] = "SELECT n.nid, n.title, n.type, g.data\n FROM node n\n JOIN {gallery_assist} g ON g.nid = n.nid\n WHERE\n g.show_in_homepage_block = 1\n AND n.uid = %d\n {$tlang}\n ORDER BY n.created DESC\n LIMIT %d";
$resT = db_query($q[$data[$delta]['bformat']], $arguments[$data[$delta]['bformat']]);
while ($r = db_fetch_object($resT)) {
$n_settings = unserialize($r->data);
$r->gallconf[$r->type] = $n_settings;
if (gallery_assist_check_public_status($r, $user)) {
$c[$r->nid] = $r;
}
}
if (empty($c)) {
return '';
}
foreach ($c as $r) {
// Menu trail.
$lattr = array();
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(1) == $r->nid || arg(0) == 'node' && arg(2) == 'edit' && is_numeric(arg(1)) && arg(1) == $r->nid || arg(1) == 'ga_edit_one' && is_numeric(arg(2)) && arg(2) == $r->nid || arg(1) == "ga_edit_one_{$r->type}" && is_numeric(arg(2)) && arg(2) == $r->nid || arg(1) == 'ga_del_one' && is_numeric(arg(2)) && arg(2) == $r->nid) {
// || (arg(3) == "edit" && is_numeric(arg(1)) && arg(1) == $r->nid)
$lattr['class'] = ' active';
}
else {
$lattr['class'] = '';
}
switch ($data[$delta]['bformat']) {
case 'pic':
if (function_exists('imagecache_preset') && is_numeric($data[$delta]['preset_id'])) {
$path = preg_replace('/\\/thm\\//', '/', $r->opath);
$c[$r->nid]->imgPath = preg_replace('/\\/files\\//', '/files/imagecache/' . $data[$delta]['preset_name'] . '/', $path);
$c[$r->nid]->imgPath2 = preg_replace('/\\/thm\\//', '/img/', $r->tpath);
}
else {
$c[$r->nid]->imgPath = preg_replace('/\\/thm\\//', '/img/', $r->tpath);
}
if (file_exists($c[$r->nid]->imgPath)) {
$imgInfo = image_get_info($c[$r->nid]->imgPath);
$imgInfo += gallery_assist_image_more_info('ga-block-' . $delta, $imgInfo, $data[$delta]);
}
else {
$imgInfo = image_get_info($c[$r->nid]->imgPath2);
$imgInfo += gallery_assist_image_more_info('ga-block-' . $delta, $imgInfo, $data[$delta]);
}
$dir = $imgInfo['pos'] == 'h' ? 'width' : 'height';
$attr[$dir] = $imgInfo["new_{$dir}"];
$attr['style'] = $imgInfo['pos'] == 'h' ? 'margin-top:' . $imgInfo['top'] . 'px;' : '';
if (function_exists('imagecache_preset') && is_numeric($data[$delta]['preset_id']) && $data[$delta]['preset_name']) {
if ($data[$delta]['disable_margin_top'] == 1) {
$attr['style'] = 'margin-top:0;';
}
$c[$r->nid]->img = theme('imagecache', $data[$delta]['preset_name'], $r->opath, $r->title, $r->title, $attr, $square);
}
else {
$c[$r->nid]->img = theme('image', file_create_url($c[$r->nid]->imgPath), $r->title, $r->title, $attr, $square);
}
$force_height = $data[$delta]['force_height'] == 1 ? $imgInfo['height'] : NULL;
$myLink[] = gallery_assist_build_block_item(l($c[$r->nid]->img, 'node/' . $r->nid, array(
'attributes' => $lattr,
'html' => TRUE,
)), 'lnk', $data[$delta], $force_height);
unset($attr);
unset($imgInfo);
break;
case 'lnk':
$myLink[] = l($c[$r->nid]->title, 'node/' . $r->nid, array(
'attributes' => $lattr,
));
break;
}
}
$output1 = $data[$delta]['bformat'] == 'pic' ? implode('', $myLink) : theme('item_list', $myLink, NULL, 'ul');
$output = empty($myLink) ? '' : '<div class="clear-block">' . $output1 . '</div>';
return array(
'subject' => $user->name . ' ' . gallery_assist_block_helper(0),
'content' => $output,
);
}
/**
* Display the GA-Block My Galleries (1).
*
*/
function _gallery_assist_block_display_1($delta) {
global $user, $language;
$u = $user->uid;
// Avoid User-ID 0 because this block is only for the owner or editor.
if ($user->uid === 0) {
return;
}
$myLink = array();
$attr = array();
// Get settings.
$data = variable_get('gallery_assist_block_data', FALSE);
$data[$delta]['thumbnail_size'] = $data[$delta]['item_size'];
$cover = $data[$delta]['bformat'] == 'pic' ? "AND p.cover = 1" : '';
$order = $data[$delta]['bformat'] == 'lnk' ? 'ORDER BY n.created DESC' : '';
$i18_n = variable_get('i18n_selection_mode', FALSE);
$i18_n = variable_get('i18n_selection_mode', FALSE);
if (module_exists('i18n') && $i18_n == 'strict') {
$tlang = "AND g.lang = '%s'";
$arguments = array(
'pic' => array(
$u,
$language->language,
$data[$delta]['visibles'] + 1,
),
'lnk' => array(
$u,
$language->language,
$data[$delta]['visibles'] + 1,
),
);
}
else {
$tlang = '';
$arguments = array(
'pic' => array(
$u,
$data[$delta]['visibles'] + 1,
),
'lnk' => array(
$u,
$data[$delta]['visibles'] + 1,
),
);
}
// Get all nodes with gallery assigned functionality.
$q['all'] = "SELECT nid, title FROM {node} WHERE uid = %d AND language = '%s'";
$q['pic'] = "SELECT n.nid, n.title, g.data, p.tpath, p.opath\n FROM {node} n\n JOIN {gallery_assist} g ON g.nid = n.nid\n JOIN {gallery_assist_item} p on p.gref = g.gref\n WHERE\n g.uid = %d\n {$tlang}\n AND p.cover = 1\n ORDER BY n.created DESC\n LIMIT %d";
$q['_lnk'] = "SELECT n.nid, n.title, g.data\n FROM {node} n\n JOIN {gallery_assist} g ON g.nid = n.nid\n WHERE\n g.uid = %d\n {$tlang}\n ORDER BY n.created DESC\n LIMIT %d";
$q['lnk'] = "SELECT n.nid, n.title, g.data, p.tpath, p.opath\n FROM {node} n\n JOIN {gallery_assist} g ON g.nid = n.nid\n JOIN {gallery_assist_item} p on p.gref = g.gref\n WHERE\n g.uid = %d\n {$tlang}\n AND p.cover = 1\n ORDER BY n.created DESC\n LIMIT %d";
$resT = db_query($q[$data[$delta]['bformat']], $arguments[$data[$delta]['bformat']]);
// while ($r = db_fetch_object($resT)) {
// $c[$r->nid] = $r;
// }
while ($r = db_fetch_object($resT)) {
$n_settings = unserialize($r->data);
$r->gallconf[$r->type] = $n_settings;
if (gallery_assist_check_public_status($r, $user)) {
$c[$r->nid] = $r;
}
}
if (empty($c)) {
return '';
}
foreach ($c as $r) {
// Menu trail.
$lattr = array();
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(1) == $r->nid || arg(0) == 'node' && arg(2) == 'edit' && is_numeric(arg(1)) && arg(1) == $r->nid || arg(1) == 'ga_edit_one' && is_numeric(arg(2)) && arg(2) == $r->nid || arg(1) == "ga_edit_one_{$r->type}" && is_numeric(arg(2)) && arg(2) == $r->nid || arg(1) == 'ga_del_one' && is_numeric(arg(2)) && arg(2) == $r->nid) {
// || (arg(3) == "edit" && is_numeric(arg(1)) && arg(1) == $r->nid)
$lattr['class'] = ' active';
}
else {
$lattr['class'] = '';
}
switch ($data[$delta]['bformat']) {
case 'pic':
if (function_exists('imagecache_preset') && is_numeric($data[$delta]['preset_id'])) {
$path = preg_replace('/\\/thm\\//', '/', $r->opath);
$c[$r->nid]->imgPath = preg_replace('/\\/files\\//', '/files/imagecache/' . $data[$delta]['preset_name'] . '/', $path);
$c[$r->nid]->imgPath2 = preg_replace('/\\/thm\\//', '/img/', $r->tpath);
}
else {
$c[$r->nid]->imgPath = preg_replace('/\\/thm\\//', '/img/', $r->tpath);
}
if (file_exists($c[$r->nid]->imgPath)) {
$imgInfo = image_get_info($c[$r->nid]->imgPath);
$imgInfo += gallery_assist_image_more_info('ga-block-' . $delta, $imgInfo, $data[$delta]);
}
else {
$imgInfo = image_get_info($c[$r->nid]->imgPath2);
$imgInfo += gallery_assist_image_more_info('ga-block-' . $delta, $imgInfo, $data[$delta]);
}
$dir = $imgInfo['pos'] == 'h' ? 'width' : 'height';
$attr[$dir] = $imgInfo["new_{$dir}"];
$attr['style'] = $imgInfo['pos'] == 'h' ? 'margin-top:' . $imgInfo['top'] . 'px;' : '';
if (function_exists('imagecache_preset') && is_numeric($data[$delta]['preset_id']) && $data[$delta]['preset_name']) {
if ($data[$delta]['disable_margin_top'] == 1) {
$attr['style'] = 'margin-top:0;';
}
$c[$r->nid]->img = theme('imagecache', $data[$delta]['preset_name'], $r->opath, $r->title, $r->title, $attr, $square);
}
else {
$c[$r->nid]->img = theme('image', file_create_url($c[$r->nid]->imgPath), $r->title, $r->title, $attr, $square);
}
$force_height = $data[$delta]['force_height'] == 1 ? $imgInfo['height'] : NULL;
$myLink[] = gallery_assist_build_block_item(l($c[$r->nid]->img, 'node/' . $r->nid, array(
'attributes' => $lattr,
'html' => TRUE,
)), 'lnk', $data[$delta], $force_height);
unset($attr);
unset($imgInfo);
break;
case 'lnk':
$myLink[] = l($c[$r->nid]->title, 'node/' . $r->nid, array(
'attributes' => $lattr,
));
break;
}
}
$more_link = '';
if (count($myLink) - 1 >= $data[$delta]['visibles']) {
array_pop($myLink);
$more_link = l('more...', 'user/' . $u . '/user_galleries');
}
$output1 = $data[$delta]['bformat'] == 'pic' ? implode('', $myLink) : theme('item_list', $myLink, NULL, 'ul');
$output = empty($myLink) ? '' : '<div class="clear-block">' . $output1 . '</div>';
$output .= $more_link;
return $output;
}
/**
* Display the GA-Block Gallery Block (2).
*/
function _gallery_assist_block_display_2($delta, $conf = NULL) {
global $user, $language;
$data = variable_get('gallery_assist_block_data', FALSE);
$data[$delta]['thumbnail_size'] = $data[$delta]['item_size'];
$block_data[$delta]['bformat'] = 'pic';
$output = '';
$in = strlen($data[$delta]['galleries']) > 0 ? explode(' ', $data[$delta]['galleries']) : '';
$n = $in[rand(0, count($in) - 1)];
$gref = db_fetch_object(db_rewrite_sql(db_query("SELECT g.gref, g.ga_public_status, g.data, g.nid, n.type FROM {gallery_assist} g JOIN {node} n ON n.nid = g.nid WHERE g.nid = %d", $n)));
// $gref->data = unserialize($gref->data);
$gref->gallconf[$gref->type] = unserialize($gref->data);
$q = "SELECT p.pid, t.nid, p.tpath, p.opath, t.ptitle, f.timestamp, n.type\n FROM {gallery_assist_item} p\n JOIN {gallery_assist_translated} t ON t.pid = p.pid AND t.gref = p.gref\n JOIN {files} f ON f.fid = p.fid\n JOIN {node} n ON n.nid = t.nid\n WHERE p.gref = %d\n ORDER BY f.timestamp " . $data[$delta]['order'] . "\n LIMIT %d";
switch ($gref->ga_public_status) {
case 'ur':
$node = node_load($gref->nid);
$display = gallery_assist_check_ur($node, 'view');
break;
case 2:
$display = gallery_assist_check_public_status($gref, $user, 'block');
break;
case 1:
$display = gallery_assist_check_public_status($gref, $user, 'block');
break;
case 0:
$display = gallery_assist_check_public_status($gref, $user, 'block');
break;
}
if (!$display) {
return '';
}
$result = db_query(db_rewrite_sql($q), $gref->gref, $data[$delta]['visibles']);
//$language->language, $gref, $data[$delta]['visibles']
while ($r = db_fetch_object($result)) {
$c[$r->pid] = $r;
}
// while ($r = db_fetch_object($resT)) {
// $n_settings = unserialize($r->data);
// $r->gallconf[$r->type] = $n_settings;
// if (gallery_assist_check_public_status($r, $user)) {
// $c[$r->nid] = $r;
// }
// }
if (empty($c)) {
return '';
}
foreach ($c as $r) {
if (function_exists('imagecache_preset') && is_numeric($data[$delta]['preset_id'])) {
$path = preg_replace('/\\/thm\\//', '/', $r->opath);
$c[$r->pid]->imgPath = preg_replace('/\\/files\\//', '/files/imagecache/' . $data[$delta]['preset_name'] . '/', $path);
$c[$r->pid]->imgPath2 = preg_replace('/\\/thm\\//', '/img/', $r->tpath);
}
else {
$c[$r->pid]->imgPath = preg_replace('/\\/thm\\//', '/img/', $r->tpath);
}
if (file_exists($c[$r->pid]->imgPath)) {
$imgInfo = image_get_info($c[$r->pid]->imgPath);
$imgInfo += gallery_assist_image_more_info('ga-block-' . $delta, $imgInfo, $data[$delta], $imgInfo['height']);
}
else {
$imgInfo = image_get_info($c[$r->pid]->imgPath2);
$imgInfo += gallery_assist_image_more_info('ga-block-' . $delta, $imgInfo, $data[$delta]);
$imgInfo['pos'] = 'v';
}
$dir = $imgInfo['pos'] == 'h' ? 'width' : 'height';
$attr[$dir] = $imgInfo["new_{$dir}"];
$attr['style'] = $imgInfo['pos'] == 'h' ? 'margin-top:' . $imgInfo['top'] . 'px;' : '';
if (function_exists('imagecache_preset') && is_numeric($data[$delta]['preset_id']) && $data[$delta]['preset_name']) {
$c[$r->pid]->img = theme('imagecache', $data[$delta]['preset_name'], $r->opath, $r->ptitle, $r->ptitle, $attr, $square);
}
else {
$c[$r->pid]->img = theme('image', file_create_url($c[$r->pid]->imgPath), $r->ptitle, $r->ptitle, $attr, $square);
}
$force_height = $data[$delta]['force_height'] == 1 ? $imgInfo['height'] : NULL;
$myLink[] = gallery_assist_build_block_item(l($c[$r->pid]->img, "node/{$r->nid}/{$r->pid}", array(
$attr,
'html' => TRUE,
)), 'pic', $data[$delta], $force_height);
unset($attr);
unset($imgInfo);
}
$output1 = implode('', $myLink);
$output = empty($output1) ? '' : '<div class="clear-block">' . $output1 . '</div>';
return $output;
}
function gallery_assist_block_t_helper($delta, $l) {
global $user;
$myTeme = empty($user->theme) ? variable_get('theme_default', FALSE) : $user->theme;
$array = array(
'gallery_assist',
$delta,
$myTeme,
);
$q = "SELECT bid FROM {blocks} WHERE module = '%s' && delta = %d && theme = '%s'";
$bid = db_result(db_query($q, $array));
$myString = "%gallery_assist:{$bid}:%";
$q3 = "SELECT s.lid FROM {locales_source} s WHERE s.location LIKE '%s'";
$lid = db_result(db_query($q3, $myString));
return $lid;
}
/**
* Build the item box for better css formating.
* It should be a theme.
* - I less it for future versions.
*/
function gallery_assist_build_block_item($link, $op = 'pic', $conf = array(), $item_height = 0) {
$attr = array(
'class' => 'gab-item-' . $op,
);
$b_img_height = $item_height > 0 ? $item_height : $conf['item_size'];
$style = 'float:left;';
$style .= $conf['item_size'] ? 'width:' . $conf['item_size'] . 'px;height:' . $b_img_height . 'px;' : 'width:50px;height:50px;';
$style .= is_numeric($conf['item_margin']) ? 'margin:' . $conf['item_margin'] . 'px;' : '';
$style .= is_numeric($conf['item_padding']) ? 'padding:' . $conf['item_padding'] . 'px;' : '';
$style .= is_numeric($conf['item_border']) ? 'border:' . $conf['item_border'] . 'px solid ' . $conf['item_border_color'] . ';' : '';
$attr['style'] = $style;
$output = '<div ' . drupal_attributes($attr) . '>';
$output .= $link;
$output .= '</div>';
return $output;
}
/**
* Theme the block output for the "Gallery Block".
* the Gallery Block shows a in the proportion minimized Gallery Assist Container.
* By more as one node setup the block shows galleries randomly.
*
* @param $boxes
* A string containing the html rendered gallery boxes.
* @param $conf
* An associative array containing the gallery settings data.
* @param $type
* A string containing the node type.
* @param $more
* Currently not used variable. Reserved for future options or conditions.
*
* @ingroup themeable
*/
function theme_gallery_assist_block_display($boxes, $conf, $type = 'gallery_assist', $more = '') {
$output = '<div id="blok-gallery-container" class="' . $type . ' gallery-container ' . $conf['op'] . ' clear-block"' . $conf['my_attr'] . '>';
$output .= $boxes;
$output .= '</div>';
return $output;
}
function _gallery_assist_block_lgsettings_form($delta) {
global $user, $language;
$form = array();
$data = variable_get('gallery_assist_block_data', FALSE);
$lgs = language_list();
foreach ($lgs as $lg) {
$form['gallery_assist_block_settings'][$lg->language] = array(
'#type' => 'textfield',
'#title' => t('@lg_name translation of your custom Block name.', array(
'@lg_name',
$lg->name,
)),
'#default_value' => $data[$delta][$lg->language]['myCustom'],
);
}
return $form;
}
/**
* Build the GA-Block settings form.
*
* @param $delta
* A integer containig the block delta.
*/
function _gallery_assist_block_settings_form($delta) {
global $user, $language;
$form = array();
$data = variable_get('gallery_assist_block_data', FALSE);
if (module_exists('i18n')) {
$form['gallery_assist_block_settings']['lg'] = array(
'#type' => 'fieldset',
'#title' => t('Custom name translation'),
'#default_value' => $data[$delta][$lg->language]['myCustom'],
'#description' => t('Translate your block custom name here'),
);
$lgs = language_list();
array_shift($lgs);
foreach ($lgs as $lg) {
$form['gallery_assist_block_settings']['lg'][$lg->language] = array(
'#type' => 'textfield',
//'#title' => $lg->name . t(' translation of your custom block name.'),
'#title' => t('@ga_block_name translation of your custom block name.', array(
'@ga_block_name' => $lg->name,
)),
'#default_value' => $data[$delta][$lg->language]['myCustom'],
);
}
}
if ($delta == 2) {
$form['gallery_assist_block_settings']['ga_block_galleries'] = array(
'#type' => 'textfield',
'#title' => t("Gallery Assist node ID's"),
'#default_value' => $data[$delta]['galleries'],
'#description' => "NID's separated with white spaces",
);
$form['gallery_assist_block_settings']['ga_block_order'] = array(
'#type' => 'select',
'#title' => t("Order"),
'#default_value' => $data[$delta]['order'],
'#options' => array(
'DESC' => 'DESC',
'ASC' => 'ASC',
),
'#description' => "Set the order to be schow the items",
);
}
if ($delta == 0 || $delta == 1) {
$form['gallery_assist_block_settings']['ga_block_bformat'] = array(
'#type' => 'radios',
'#title' => t('Gallery Assist block items format'),
'#options' => array(
'lnk' => 'as links',
'pic' => 'as icons',
),
'#default_value' => $data[$delta]['bformat'],
);
}
if ($data[$delta]['bformat'] == 'pic' && $delta == 0 || $data[$delta]['bformat'] == 'pic' && $delta == 1 || $delta == 2) {
$form['gallery_assist_block_settings']['ga_block_item_size'] = array(
'#type' => 'textfield',
'#title' => t('Item size'),
'#default_value' => $data[$delta]['item_size'],
'#description' => 'Block thumbnail size. Is a ImageCache preset selected, this field will takeover the sizes from the preset action.',
'#size' => 8,
);
if (function_exists('imagecache_preset')) {
$form['gallery_assist_block_settings']['ga_block_ic_sizes'] = array();
$form['gallery_assist_block_settings']['ga_block_ic_sizes'] = _gallery_assist_get_ic_blocksettings_form($data[$delta]);
}
$form['gallery_assist_block_settings']['ga_block_item_margin'] = array(
'#type' => 'select',
'#title' => t('Item margin'),
'#options' => drupal_map_assoc(array(
t('none'),
1,
2,
3,
4,
5,
6,
7,
8,
9,
)),
'#default_value' => $data[$delta]['item_margin'],
);
$form['gallery_assist_block_settings']['ga_block_item_padding'] = array(
'#type' => 'select',
'#title' => t('Item padding'),
'#options' => drupal_map_assoc(array(
'none',
1,
2,
3,
4,
5,
6,
7,
8,
9,
)),
'#default_value' => $data[$delta]['item_padding'],
);
$form['gallery_assist_block_settings']['ga_block_item_border'] = array(
'#type' => 'select',
'#title' => t('Item border'),
'#options' => drupal_map_assoc(array(
'none',
1,
2,
3,
4,
5,
6,
7,
8,
9,
)),
'#default_value' => $data[$delta]['item_border'],
);
$form['gallery_assist_block_settings']['ga_block_item_border_color'] = array(
'#type' => 'textfield',
'#title' => t('Item border color #027AC6'),
'#default_value' => $data[$delta]['item_border_color'],
'#size' => 8,
);
}
if ($user->id == 1) {
$visibles = $data[$delta]['visibles'];
$desc = 'Nummber of items visible in the block';
}
else {
$visibles = $data[$delta]['visibles'] <= 12 ? $data[$delta]['visibles'] : 12;
$desc = 'Nummber of items visible in the block (1 - 12).';
}
$form['gallery_assist_block_settings']['ga_block_visibles'] = array(
'#type' => 'textfield',
'#title' => t('Gallery Assist visible nodes'),
'#default_value' => $visibles,
'#description' => $desc,
'#size' => 8,
);
return $form;
}
function gallery_assist_block_helper($delta) {
global $language;
$data = variable_get('gallery_assist_block_data', FALSE);
$block_names = array(
0 => !empty($data[$delta][$language->language]['myCustom']) ? $data[$delta][$language->language]['myCustom'] : t('Galleries'),
1 => !empty($data[$delta][$language->language]['myCustom']) ? $data[$delta][$language->language]['myCustom'] : t('My Galleries'),
2 => !empty($data[$delta][$language->language]['myCustom']) ? $data[$delta][$language->language]['myCustom'] : t('Gallery Block'),
);
return $block_names[$delta];
}
/**
* Save the GA-Block settings.
*/
function _gallery_assist_block_settings_form_submit($delta, $post_data) {
global $user, $language;
//gallery_assist_invalidate_cache();
$cq = "TRUNCATE TABLE {cache_gallery_assist_data}";
db_query($cq, $node->nid);
$prefix = 'ga_block_';
$data = variable_get('gallery_assist_block_data', FALSE);
if (module_exists('i18n')) {
$myTeme = empty($user->theme) ? variable_get('theme_default', FALSE) : $user->theme;
$array = array(
'gallery_assist',
$delta,
$myTeme,
);
$lgs = language_list();
array_shift($lgs);
foreach ($lgs as $lg) {
if (empty($post_data[$lg->language])) {
continue;
}
$data[$delta][$lg->language]['myCustom'] = $post_data[$lg->language];
$q = "SELECT bid FROM {blocks} WHERE module = '%s' && delta = %d && theme = '%s'";
$bid = db_result(db_query($q, $array));
$myString = "%gallery_assist:{$bid}:%";
$q3 = "SELECT s.lid FROM {locales_source} s JOIN {locales_target} t WHERE s.location LIKE '%s'";
$lid = db_result(db_query($q3, $myString));
if (!empty($post_data[$lg->language])) {
db_query("UPDATE {locales_target} set translation = '%s' WHERE lid = %d AND language = '%s'", $data[$delta][$lg->language]['myCustom'], $lid, $lg->language);
}
}
}
if ($delta == 2) {
$data[$delta]['galleries'] = $post_data[$prefix . 'galleries'] ? $post_data[$prefix . 'galleries'] : $data[$delta]['galleries'];
$data[$delta]['visibles'] = $post_data[$prefix . 'visibles'] ? $post_data[$prefix . 'visibles'] : $data[$delta]['visibles'];
$data[$delta]['order'] = $post_data[$prefix . 'order'] ? $post_data[$prefix . 'order'] : $data[$delta]['order'];
}
if ($delta == 0 || $delta == 1) {
$data[$delta]['bformat'] = $post_data[$prefix . 'bformat'] ? $post_data[$prefix . 'bformat'] : $data[$delta]['bformat'];
}
if ($delta == 0 || $delta == 1 || $delta == 2) {
$data[$delta]['item_size'] = $post_data[$prefix . 'item_size'] ? $post_data[$prefix . 'item_size'] : $data[$delta]['item_size'];
$data[$delta]['item_margin'] = $post_data[$prefix . 'item_margin'] ? $post_data[$prefix . 'item_margin'] : $data[$delta]['item_margin'];
$data[$delta]['item_padding'] = $post_data[$prefix . 'item_padding'] ? $post_data[$prefix . 'item_padding'] : $data[$delta]['item_padding'];
$data[$delta]['item_border'] = $post_data[$prefix . 'item_border'] ? $post_data[$prefix . 'item_border'] : $data[$delta]['item_border'];
$data[$delta]['item_border_color'] = $post_data[$prefix . 'item_border_color'] ? $post_data[$prefix . 'item_border_color'] : $data[$delta]['item_border_color'];
$data[$delta]['visibles'] = $post_data[$prefix . 'visibles'] ? $post_data[$prefix . 'visibles'] : $data[$delta]['visibles'];
if (function_exists('imagecache_preset') && is_numeric($post_data[$prefix . 'presetid'])) {
$preset = imagecache_preset($post_data[$prefix . 'presetid']);
$data[$delta]['preset_id'] = $preset['presetid'];
$data[$delta]['preset_name'] = $preset['presetname'];
$data[$delta]['preset_width'] = $preset['actions'][count($preset['actions']) - 1]['data']['width'];
$data[$delta]['preset_height'] = $preset['actions'][count($preset['actions']) - 1]['data']['height'];
$data[$delta]['item_size'] = $data[$delta]['preset_width'];
$data[$delta]['force_height'] = $post_data[$prefix . 'force_height'];
$data[$delta]['disable_margin_top'] = $post_data[$prefix . 'disable_margin_top'];
}
else {
$data[$delta]['preset_id'] = 'none';
unset($data[$delta]['preset_name']);
unset($data[$delta]['preset_width']);
unset($data[$delta]['preset_height']);
unset($data[$delta]['item_size']);
$data[$delta]['item_size'] = empty($post_data[$prefix . 'item_size']) ? 50 : $post_data[$prefix . 'item_size'];
}
}
variable_set('gallery_assist_block_data', $data);
}
/**
* Build the select field with the presets list.
*
* @param $c
* @return
* An array containing the form select field.
*/
function _gallery_assist_get_ic_blocksettings_form($c) {
$form = array();
$presets = imagecache_presets($settings);
$options = array(
'none' => 'none',
);
foreach ($presets as $presetid => $value) {
$options[$presetid] = $value['presetname'];
}
$form['gallery_assist_block_sizes']['ga_block_presetid'] = array(
'#type' => 'select',
'#title' => t('Thumbnail preset'),
'#default_value' => $c['preset_id'],
'#options' => $options,
'#description' => t('Current used setting: @thm_presetname', array(
'@thm_presetname' => $c['preset_name'],
)),
);
$form['gallery_assist_block_sizes']['ga_block_force_height'] = array(
'#type' => 'checkbox',
'#title' => t('Force the Item height'),
'#default_value' => $c['force_height'],
'#description' => t('Enabled will be forced the height of the box to the image height.'),
);
$form['gallery_assist_block_sizes']['ga_block_disable_margin_top'] = array(
'#type' => 'checkbox',
'#title' => t('Disable margin-top'),
'#default_value' => $c['disable_margin_top'],
'#description' => t('Set margin-top to 0 if needed.'),
);
return $form;
}
/**
* Calculate necessary parameters to build the gallery item boxes.
*
* @param $type
* A string containing the node type.
* @param $img
* An associative array containing the gallery item data.
* @param $conf
* An associative array containing the gallery settings data.
* @param $my_image_height
* A integer containing the image height if force_image_height is setted to TRUE.
*/
function gallery_assist_image_more_info($type, $img, $conf, $my_image_height = '') {
$symbol = $conf['force_image_height'] == 1 ? $my_image_height : $conf['thumbnail_size'];
$img['padding'] = $conf['item_padding'];
$img['margin'] = $conf['item_margin'];
$img['dsize'] = $conf['thumbnail_size'];
$img['pos'] = $img['height'] >= $img['width'] ? 'v' : 'h';
if ($img['pos'] == 'h') {
$img['new_width'] = $symbol;
$img['new_height'] = $img['new_width'] * 100 / $img['width'] * $img['height'] / 100;
$minus = $conf['force_image_height'] == 1 ? $conf['thumbnail_height_size'] : $img['new_height'];
$img['top'] = $img['height'] < $img['width'] ? ($symbol - $minus) / 2 : 0;
}
else {
$img['new_height'] = $symbol;
}
if ($conf['disable_margin_top'] == 1) {
unset($img['top']);
}
return $img;
}
function gallery_assist_image_prev_more_info($img, $conf) {
$direction = $img['width'] > $img['height'] ? 'width' : 'height';
$contra = $img['width'] > $img['height'] ? 'height' : 'width';
if ($img[$direction] > $conf['preview_size']) {
$ratio = $conf['preview_size'] / $img[$direction];
$img["new_{$direction}"] = $conf['preview_size'];
$img["new_{$contra}"] = $img[$contra] * $ratio;
}
else {
$img["new_{$direction}"] = $img[$direction];
$img["new_{$contra}"] = $img[$contra];
}
return $img;
}
/**
*
* name: gallery_assist_get_preset_sizes().
* @param
* @return
*/
function gallery_assist_get_preset_more_info($presetid) {
if (empty($presetid)) {
return FALSE;
}
$data = array();
$preset = imagecache_preset($presetid);
$data['preset_id'] = $preset['presetid'];
$data['preset_name'] = $preset['presetname'];
$data['preset_width'] = $preset['actions'][count($preset['actions']) - 1]['data']['width'];
$data['preset_height'] = $preset['actions'][count($preset['actions']) - 1]['data']['height'];
$data['direction'] = $data['preset_width'] > $data['preset_height'] ? 'height' : 'width';
return $data;
}
/**
* Implementation of hook_flush_caches().
*/
function gallery_assist_flush_caches() {
return array(
'cache_gallery_assist_data',
);
}
/**
* Invalidate the gallery_assist cache, forcing a rebuild on the next grab of table data.
*/
function gallery_assist_invalidate_cache($cid = "*", $table = 'cache_gallery_assist_data', $wildcard = FALSE) {
cache_clear_all($cid, $table, $wildcard);
}
/**
* Load the needed css- and js-files form submodule lightboxes.
*/
function gallery_assist_get_includes($hilfo = array()) {
if (empty($hilfo)) {
return;
}
if (count($hilfo['data']['css'])) {
foreach ($hilfo['data']['css'] as $k => $v) {
if ($v) {
drupal_add_css($k);
}
}
}
if (count($hilfo['data']['js'])) {
foreach ($hilfo['data']['js'] as $k => $v) {
if ($v) {
drupal_add_js($k);
}
}
}
if (count($hilfo['data']['selector'])) {
foreach ($hilfo['data']['selector'] as $k => $v) {
if ($v) {
drupal_add_js($k);
}
}
}
}
/**
* Implementation of hook_content_extra_fields().
*
* Lets CCK expose the gallery content weight in the node content (only if CCK is installed).
*/
function gallery_assist_content_extra_fields($type_name) {
// if ($type_name == 'gallery_assist') {
// $extra['gallery_assist'] = array(
// 'label' => t('Gallery Assist Container'),
// 'description' => t('Container with the Gallery Assist items.'),
// 'weight' => 0,
// );
// return $extra;
// }
$extra['u1'] = array(
'label' => t('Uno Container'),
'description' => t('Container with the Gallery Assist items.'),
'weight' => 0,
);
$extra['u2'] = array(
'label' => t('Dos Container'),
'description' => t('Container with the Gallery Assist items.'),
'weight' => 2,
);
$extra['u3'] = array(
'label' => t('Tres Container'),
'description' => t('Container with the Gallery Assist items.'),
'weight' => 2,
);
return $extra;
}
/**
* Here are planed the export, rebuild or any other operation.
*/
function gallery_assist_recovery(&$form, $form_state, $form_id) {
// will come later...
return '';
}
/**
* Advice administrator in case they delete modules
* from the drupal installation without using the administration as well.
*/
function gallery_assist_panic() {
// will come later...
return 'I am in panic ;-)';
}
/**
* Include gallery_assist .css files.
* A beautifull merlinofcaos function
*/
function gallery_assist_add_css($file) {
drupal_add_css(drupal_get_path('module', 'gallery_assist') . "/css/{$file}.css");
}
/**
* Include gallery_assist .js files.
* A beautifull merlinofcaos function
*/
function gallery_assist_add_js($file) {
drupal_add_js(drupal_get_path('module', 'gallery_assist') . "/js/{$file}.js");
}
/**
* Include gallery_assist .js files if not loaded.
*/
function _gallery_assist_lb_includes() {
// Set the jQuery.extend Drupal.settings only once in teaser lists.
$lightbox_conf = drupal_get_js();
if (!preg_match("/lightbox_conf/", $lightbox_conf)) {
$data = variable_get('gallery_assist_lightbox_data', FALSE);
//$data['the_path'] = 'node/'. $node->nid .'/'. $data['the_path'];
$js_settings = array(
'lightbox_conf' => array(
variable_get('gallery_assist_lightbox', 'none') => $data,
),
);
drupal_add_js($js_settings, 'setting');
}
}
/**
* Implementation of hook_token_list().
*/
function gallery_assist_token_list($type = 'all') {
if ($type == 'node' || $type == 'all') {
$tokens['item']['ga-pid'] = t("The image ID");
$tokens['item']['ga-ptitle'] = t("Image name");
$tokens['item']['ga-palt'] = t("Image alternative text");
$tokens['item']['ga-pdescription'] = t("Image Caption");
$tokens['item']['ga-copyright'] = t("Image copyright information");
$tokens['node']['ga-gref'] = t("The gallery referenced ID.");
$tokens['node']['ga-ref'] = t("The gallery referenced node ID.");
return $tokens;
}
}
/**
* Implementation of hook_token_values().
*/
function gallery_assist_token_values($type, $object = NULL, $options = array()) {
if ($type == 'node' && variable_get("gallery_assist_{$object->type}", 0)) {
$tokens['ga-pid'] = $object->gallitems['pid'];
$tokens['ga-ptitle'] = TRUE;
$tokens['ga-palt'] = $object->gallitems[$node->gallitems['pid']]['palt'];
$tokens['ga-pdescription'] = $object->gallitems[$node->gallitems['pid']]['pdescription'];
$tokens['ga-copyright'] = $object->gallitems[$node->gallitems['pid']]['copyright'];
$tokens['ga-gref'] = $object->gref;
$tokens['ga-ref'] = $object->ref;
return $tokens;
}
}
/**
* Clear the Gallery Assist cache table.
*/
function gallery_assist_clearthecache($nid = 0) {
if ($nid > 0) {
db_query("DELETE FROM {cache_gallery_assist_data} WHERE cid = '%s'", $nid);
}
else {
$cq = "TRUNCATE TABLE {cache_gallery_assist_data}";
db_query($cq);
}
$form_state['redirect'] = '/admin/settings/gallery_assist/extras';
drupal_set_message('Gallery Assist Cache cleared');
}
/**
* Implementation of hook_file_download.
*/
function gallery_assist_file_download($filepath) {
global $user;
// Check the original preset because img, thm and prev are not listed in the files table.
if (preg_match('/prev/', $filepath) || preg_match('/thm/', $filepath) || preg_match('/img/', $filepath)) {
$filepath = preg_replace('/prev\\//', '', $filepath);
$filepath = preg_replace('/thm\\//', '', $filepath);
$filepath = preg_replace('/img\\//', '', $filepath);
}
// Return headers for images.
$path = file_create_path($filepath);
if (!($path && file_exists($path))) {
return;
}
$q = "SELECT f.*, p.nid, n.type FROM {files} f JOIN {gallery_assist_item} p ON p.fid=f.fid JOIN {node} n ON n.nid=p.nid WHERE filepath='%s'";
//$file = db_fetch_object(db_query(db_rewrite_sql($q), $filepath));
if (!($file = db_fetch_object(db_query(db_rewrite_sql($q), $path)))) {
return;
}
if ($user->uid == 1 || $user->uid == $file->uid || gallery_assist_check_access($node)) {
return array(
'Content-Type: ' . $file->filemime,
'Content-Length: ' . (int) $file->filesize,
);
}
else {
return -1;
}
}
/**
* Provide the GA content type assignments.
*
* @param boolean $all
* False is default and means only assigments. TRUE means all assigments and gallery_assist.
* @return array $assignments
* The array ist keyed with types an contains the type names.
*/
function gallery_assist_get_assignments($all = FALSE) {
$assignments = array();
$types = node_get_types('names');
if (!$all) {
unset($types['gallery_assist']);
}
foreach ($types as $type => $name) {
if (variable_get('gallery_assist_' . $type, 0) == 1) {
$assignments[$type] = $name;
}
}
return $assignments;
}
/**
* This function print the copyright of this module at the back-end interface.
*
* @ingroup forms
*/
function gallery_assist_info_line() {
return t('Module developed by <a target="_blank" href="@ga_creator_link">Juan Morejón</a> from the <a target="_blank" href="@qtg_link">Quiptime Group</a>', array(
'@ga_creator_link' => url('http://simple.puntolatinoclub.de'),
'@qtg_link' => url('http://www.quiptime.com'),
));
}
/**
* Implementation of hook_node_operations().
*/
function gallery_assist_node_operations() {
$operations = array(
'ga_p_promote' => array(
'label' => t('Gallery Assist: Promote to the user profile'),
'callback' => 'gallery_assist_mass_updates',
'callback arguments' => array(
'updates' => array(
'in_profile' => 1,
),
),
),
'ga_p_demote' => array(
'label' => t('Gallery Assist: Demote from user profile'),
'callback' => 'gallery_assist_mass_updates',
'callback arguments' => array(
'updates' => array(
'in_profile' => 0,
),
),
),
'ga_add to gblock' => array(
'label' => t('Gallery Assist: Show in block'),
'callback' => 'gallery_assist_mass_updates',
'callback arguments' => array(
'updates' => array(
'show_in_homepage_block' => 1,
),
),
),
'ga_remove from gblock' => array(
'label' => t('Gallery Assist: Remove from block'),
'callback' => 'gallery_assist_mass_updates',
'callback arguments' => array(
'updates' => array(
'show_in_homepage_block' => 0,
),
),
),
'ga_public_status_pb' => array(
'label' => t('Gallery Assist: Public'),
'callback' => 'gallery_assist_mass_updates',
'callback arguments' => array(
'updates' => array(
'ga_public_status' => 0,
),
),
),
'ga_public_status_pba' => array(
'label' => t('Gallery Assist: Privat'),
'callback' => 'gallery_assist_mass_updates',
'callback arguments' => array(
'updates' => array(
'ga_public_status' => 1,
),
),
),
'ga_public_status_prv' => array(
'label' => t('Gallery Assist: Public for all'),
'callback' => 'gallery_assist_mass_updates',
'callback arguments' => array(
'updates' => array(
'ga_public_status' => 2,
),
),
),
);
return $operations;
}
function gallery_assist_mass_updates($nodes, $updates) {
// We use batch processing to prevent timeout when updating a large number
// of nodes.
if (count($nodes) > 5) {
$batch = array(
'operations' => array(
array(
'_gallery_assist_mass_updates_batch_process',
array(
$nodes,
$updates,
),
),
),
'finished' => '_gallery_assist_mass_updates_batch_finished',
'title' => t('GA Processing test'),
// We use a single multi-pass operation, so the default
// 'Remaining x of y operations' message will be confusing here.
'progress_message' => '',
'error_message' => t('The update has encountered an error.'),
);
batch_set($batch);
}
else {
foreach ($nodes as $nid) {
_gallery_assist_mass_updates_helper($nid, $updates);
}
drupal_set_message(t('The update has been performed.'));
}
}
function _gallery_assist_mass_updates_helper($nid, $updates) {
foreach ($updates as $name => $value) {
$changed = FALSE;
if ($name == 'in_profile') {
db_query("UPDATE {gallery_assist} SET in_profile = %d WHERE nid = %d", $value, $nid);
$changed = TRUE;
}
elseif ($name == 'show_in_homepage_block') {
db_query("UPDATE {gallery_assist} SET show_in_homepage_block = %d WHERE nid = %d", $value, $nid);
$changed = TRUE;
}
elseif ($name == 'ga_public_status') {
db_query("UPDATE {gallery_assist} SET ga_public_status = %d WHERE nid = %d", $value, $nid);
$changed = TRUE;
}
if ($changed) {
db_query("DELETE FROM {cache_gallery_assist_data} WHERE cid = '%s'", $nid);
}
}
$node = node_load($nid, NULL, TRUE);
return $node;
}
function _gallery_assist_mass_updates_batch_finished() {
}
function _gallery_assist_mass_updates_batch_process($nodes, $updates, &$context) {
if (!isset($context['sandbox']['progress'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['max'] = count($nodes);
$context['sandbox']['nodes'] = $nodes;
}
// Process nodes by groups of 5.
$count = min(10, count($context['sandbox']['nodes']));
for ($i = 1; $i <= $count; $i++) {
// For each nid, load the node, reset the values, and save it.
$nid = array_shift($context['sandbox']['nodes']);
$node = _gallery_assist_mass_updates_helper($nid, $updates);
// Store result for post-processing in the finished callback.
$context['results'][] = l($node->title, 'node/' . $node->nid);
// Update our progress information.
$context['sandbox']['progress']++;
}
// Inform the batch engine that we are not finished,
// and provide an estimation of the completion level we reached.
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}
/**
* Function from ericpai to simulate a multiple pages pager.
* It calculate all necessary parameters to add pages links to the GA-Pager.
*
* @param object $node
* @param integer $page
* @param integer $pages
* @param array $link
* @return a string containing the rendered pager.
*/
function gallery_assist_emulate_pager_pages(&$node, $page, $pages, $link) {
$nav = array();
for ($i = 1; $i < $pages + 1; $i++) {
if ($page == $i) {
// Bold the page and dont make it a link
$nav[] = '<b>' . $i . '</b>';
}
else {
// Link the page
$nav[] = l($i, "node/{$node->nid}", array(
'attributes' => array(
'title' => "{$page}/{$pages}",
),
'query' => array(
'page' => $i,
),
));
}
}
$my_n = $my_odd == 1 ? 0 : 1;
$my_page = $page;
$my_quantity = 4;
$my_middle = ceil($my_quantity / 2);
$my_short = 1;
$my_total = $pages;
$links = $nav;
if ($my_short == 1 && $my_total > $my_quantity) {
if ($my_page > $my_total - $my_quantity) {
if ($my_page + $my_middle - $my_odd < $my_total) {
$mysmall = array_slice($links, $my_page - $my_middle, $my_quantity, TRUE);
}
else {
$mysmall = array_slice($links, $my_total - $my_quantity, $my_quantity, TRUE);
}
}
elseif ($my_page <= $my_quantity) {
if ($my_page >= $my_middle) {
$mysmall = array_slice($links, $my_page - $my_middle, $my_quantity, TRUE);
}
else {
$mysmall = array_slice($links, 0, $my_quantity, TRUE);
}
}
else {
$mysmall = array_slice($links, $my_page - $my_middle, $my_middle + $my_middle - $my_odd, TRUE);
}
}
else {
$mysmall = $nav;
}
if ($my_total > $my_quantity) {
if (count($link) > 1) {
array_unshift($mysmall, $link[0]);
array_push($mysmall, $link[1]);
}
else {
if (count($link)) {
if (preg_match('/previou/', $link[0])) {
array_unshift($mysmall, $link[0]);
}
if (preg_match('/next/', $link[0])) {
array_push($mysmall, $link[0]);
}
}
}
}
$attributes = array(
'class' => "{$node->type} pager",
'style' => 'text-align: center;',
);
$my_pager = theme('item_list', $mysmall, NULL, 'ul', $attributes);
return $my_pager;
}
/**
* Build gallery items link acording the settings.
*
* @param $my_img
* A string containing the rended image tag.
* @param $item
* An object containing all necessary parameters from the item (image).
* @param $link_query
* An array with data to be used as fragment or extra queries for the hyperlink.
* @param $conf
* An array containing the gallery settings from current assignment.
*
* @return An html string containing the rendered hyperlink.
*/
function gallery_assist_build_item_hyperlink($my_img, $item, $link_query, $conf) {
// Build the teaser thumbnail links.
if ($conf['opt'] == 'teaser') {
switch ($conf['t_thm_link_format']) {
case 'none':
$thm_link = $my_img;
break;
case 'node':
$thm_link = l($my_img, 'node/' . $item->my_nid, array(
'html' => TRUE,
'query' => $link_query,
));
break;
case 'item':
if (empty($conf['ga_overwrite_hyperlink'])) {
$thm_link = l($my_img, 'node/' . $item->my_nid . '/' . $item->pid, array(
'html' => TRUE,
'query' => $link_query,
));
}
else {
$thm_link = $conf['ga_overwrite_hyperlink'];
}
break;
}
}
else {
if (empty($conf['ga_overwrite_hyperlink'])) {
$thm_link = l($my_img, 'node/' . $item->my_nid . '/' . $item->pid, array(
'html' => TRUE,
'query' => $link_query,
));
}
else {
$thm_link = $conf['ga_overwrite_hyperlink'];
}
}
return $thm_link;
}
/**
* Update the public status fron all existing galleries from an assignment.
*
* @param $type
* A string with the node type.
* @param $status
* A integer with the selected status id.
*/
function gallery_assist_public_status_updater($type, $status) {
if (empty($type)) {
return;
}
$names = array(
0 => t('public'),
1 => t('privat'),
2 => t('public for all'),
);
$q = "SELECT g.gid, g.nid, n.type FROM {gallery_assist} g, {node} n WHERE g.nid = n.nid AND n.type = '%s'";
$result = db_rewrite_sql(db_query($q, $type));
$i = 0;
while ($r = db_fetch_object($result)) {
++$i;
db_query("UPDATE {gallery_assist} SET ga_public_status = %d WHERE gid = %d", $status, $r->gid);
db_query("DELETE FROM {cache_gallery_assist_data} WHERE cid = %d", $r->nid);
}
if ($i == 1) {
$message = 'One gallery was updated with public status = @status.';
}
elseif ($i > 1) {
$message = '@num galleries were updated with public status = @status.';
}
else {
return;
}
drupal_set_message($message);
}
function gallery_assist_form_help_links($node) {
$form = array();
$iu = $node->uid > 0 && $user->uid > 0 ? 1 : '';
if ($iu > 0 && $node->uid == 1 || user_access('administer gallery_assist') || user_access('administer_gallery assist_' . $node->type)) {
if ($node->type == 'gallery_assist') {
$myPath = 'gallery_assist/assignments';
}
elseif (variable_get('gallery_assist_' . $node->type, 0) == 1) {
$myPath = 'gallery_assist/assignments/' . $node->type;
}
}
$node_type_name = node_get_types('type', $node->type);
$markup_value = t('Edit the settings from Gallery Assist for this content type -> <a href="@myPath">%contenType</a>', array(
'@myPath' => url('admin/settings/' . $myPath),
'%contenType' => $node_type_name->name,
));
$form['assignment_settings_link'] = array(
'#type' => 'markup',
'#value' => '<div id="ga-devel-by">' . $markup_value . '</div>',
'#weight' => -100,
'#access' => user_access('administer gallery_assist', $user) || user_access('administer gallery_assist_' . $node->type, $user) ? TRUE : FALSE,
);
return $form;
}
function gallery_assist_sorting_items_standard($form_state, $node) {
$form = array();
$conf = $node->gallconf[$node->type];
$conf['thumbnail_size'] = 50;
$form = array(
'#theme' => 'gallery_assist_form_new',
'#cache' => TRUE,
'#weight' => 0,
);
$form['gallery_items']['#theme'] = 'gallery_assist_sort_form_current';
$form['gallery_items']['#tree'] = TRUE;
// Build links.
$_GET['unlimited'] = 1;
if (isset($_GET['unlimited']) && $_GET['unlimited'] > 0) {
$title = 'paged';
$attributes = array(
'attributes' => array(
'title' => 'Use pager in case of great number of images.',
'class' => 'button',
),
);
$value = '<strong>all</strong> | ' . l($title, "node/{$node->nid}/edit/ga_sort/no_jquery", $attributes);
$links[] = '<strong>all</strong>';
// $links[] = l($title, "node/{$node->nid}/edit/ga_sort/no_jquery", $attributes);
$links[] = '<strike>paged</strike>';
}
else {
$title = 'all';
$attributes = array(
'query' => array(
'unlimited' => 1,
),
'attributes' => array(
'title' => 'Load all images.',
),
);
$value = l($title, "node/{$node->nid}/edit/ga_sort/no_jquery", $attributes) . ' | <strong>paged</strong>';
$links[] = l($title, "node/{$node->nid}/edit/ga_sort/no_jquery", $attributes);
$links[] = '<strong>paged</strong>';
}
// $links[] = '<button onclick="alert($(\'DIV#sort-items\').sortable(\'serialize\'))" type="button">Serialize!</button>';
if (module_exists('gallery_assist_ui')) {
$links[] = l('JQuery', "node/{$node->nid}/edit/ga_sort", $attributes);
}
$form['sort_container_top'] = array(
'#type' => 'fieldset',
'#weight' => -50,
);
$form['sort_container_top']['links'] = array(
'#type' => 'markup',
'#value' => implode(' | ', $links),
);
$order = isset($_GET['gao']) && !empty($_GET['gao']) ? $_GET['gao'] : $conf['ga_db_order'];
$order_field = isset($_GET['gaof']) && !empty($_GET['gaof']) ? $_GET['gaof'] : 'a.weight';
$ga_cover_sticky = $conf['ga_cover_sticky'] == 1 ? 'a.cover DESC, ' : '';
$query = "SELECT a.*, t.*, f.timestamp\n FROM {gallery_assist_item} a, {gallery_assist_translated} t, {files} f\n WHERE a.pid = t.pid\n AND a.fid = f.fid\n AND t.nid = %d\n ORDER BY {$ga_cover_sticky} {$order_field} {$order}";
//. tablesort_sql($header);
$result = db_query($query, $node->nid);
while ($item = db_fetch_object($result)) {
$img = image_get_info($item->tpath);
$img = gallery_assist_image_more_info($type, $img, $conf);
$direction = $img['pos'] == h ? 'width' : 'height';
$img_attr = array(
$direction => $conf['thumbnail_size'],
);
$path = explode('/', $item->opath);
$filename = array_pop($path);
$path[] = 'img';
$path[] = $filename;
$path = implode('/', $path);
$image = theme('image', $path, $item->palt, $item->ptitle, $img_attr, FALSE);
$image = l($image, "node/{$node->nid}/{$item->pid}", array(
'html' => true,
));
$form['gallery_items'][$item->pid]['item'] = array(
'#value' => $image,
);
$form['gallery_items'][$item->pid]['nid'] = array(
'#value' => $node->nid,
);
$form['gallery_items'][$item->pid]['pid'] = array(
'#value' => $item->pid,
);
$form['gallery_items'][$item->pid]['ptitle'] = array(
'#value' => $item->ptitle,
);
//
$form['gallery_items'][$item->pid]['uploaded'] = array(
'#value' => $item->timestamp,
);
//
$form['gallery_items'][$item->pid]['weight'] = array(
'#type' => 'weight',
'#delta' => count($node->gallitems),
'#default_value' => $item->weight,
'#attributes' => array(
'class' => 'gallery-assist-weight',
),
);
if ($item->cover == 1) {
$form['ga_cover_id'] = array(
'#type' => 'hidden',
'#value' => $item->pid,
);
}
}
$form['node_type'] = array(
'#type' => 'hidden',
'#value' => $node->type,
);
$form['node_nid'] = array(
'#type' => 'hidden',
'#value' => $node->nid,
);
$form['ga_db_order'] = array(
'#type' => 'hidden',
'#value' => $conf['ga_db_order'],
);
$form['ga_cover_sticky'] = array(
'#type' => 'hidden',
'#value' => $conf['ga_cover_sticky'],
);
$form['gallery_items']['#weight'] = 20;
$pager_limit = variable_get('gallery_assist_editform_pager_limit', 25);
$form['gallery_items']['#prefix'] = theme('pager', NULL, $pager_limit, 0, NULL, 5);
$form['gallery_items']['#suffix'] = theme('pager', NULL, $pager_limit, 0, NULL, 5);
$form['sort_container_bottom'] = array(
'#type' => 'fieldset',
'#weight' => 50,
);
$form['sort_container_bottom']['links'] = array(
'#type' => 'markup',
'#value' => implode(' | ', $links),
);
$form['#submit'][] = 'gallery_assist_standard_sort_submit';
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 100,
);
return $form;
}
function theme_gallery_assist_sort_form_current($form) {
$header = array(
'',
t('Image'),
array(
'data' => t('Title'),
'field' => 'ptitle',
'style' => 'width: 300px;',
),
array(
'data' => t('Uploaded'),
'field' => 'timestamp',
),
'',
array(
'data' => t('Weight'),
'field' => 'weight',
'sort' => $conf['ga_db_order'],
),
);
// Define the output as draggable table
drupal_add_tabledrag('gallery-assist-list', 'order', 'sibling', 'gallery-assist-weight');
$rows = array();
foreach (element_children($form) as $key) {
// Add class to group weight fields for drag and drop.
$form[$key]['weight']['#attributes']['class'] = 'gallery-assist-weight';
// Fill the table cells
$row = array(
'',
);
$row[] = array(
'data' => drupal_render($form[$key]['item']),
'style' => 'text-align: center;',
);
$row[] = array(
'data' => drupal_render($form[$key]['ptitle']),
'style' => 'width: 300px;white-space:nowrap;',
);
$df = t('Y/m/d');
//$uploaded = $form[$key]['uploaded']['#default_value'] =
$row[] = array(
'data' => format_date($form[$key]['uploaded']['#default_value'], 'custom', $df),
);
$row[] = array(
'data' => l(t('edit'), "node/{$form[$key]['nid']['#value']}/{$form[$key]['pid']['#value']}/edit"),
'style' => 'width: 100%;',
);
$row[] = drupal_render($form[$key]['weight']);
// Build the row with dragable class
$rows[] = array(
'data' => $row,
'class' => 'draggable',
);
}
$output = theme('table', $header, $rows, array(
'id' => 'gallery-assist-list',
));
//$output .= drupal_render($form);
return $output;
}
function gallery_assist_standard_sort_submit(&$form, $form_state) {
if (count($form_state['values']['gallery_items']) > 0) {
$sort = 0;
foreach ($form_state['values']['gallery_items'] as $pid => $w) {
$weights[$pid] = $w['weight'];
$pids[$w['weight']] = $pid;
if ($w['weight'] < 0) {
$sort = $sort + 1;
}
}
if ($sort > 0) {
ksort($pids);
$cover = $pids[min($weights)];
$i = $form_state['values']['ga_db_order'] == 'DESC' ? count($form_state['values']['gallery_items']) : 0;
foreach ($pids as $weight => $pid) {
db_query("UPDATE {gallery_assist_item} SET weight = %d WHERE pid = %d", $i, $pid);
if ($form_state['values']['ga_db_order'] == 'DESC') {
--$i;
}
else {
++$i;
}
if ($form_state['values']['ga_cover_sticky'] == 1 && $pid == $cover) {
gallery_assist_cover_updater($form_state['values']['node_nid'], $cover);
}
}
gallery_assist_clearthecache($form_state['values']['node_nid']);
}
}
}
Functions
Name![]() |
Description |
---|---|
gallery_assist_access | Implementation of hook_access(). |
gallery_assist_add_css | Include gallery_assist .css files. A beautifull merlinofcaos function |
gallery_assist_add_js | Include gallery_assist .js files. A beautifull merlinofcaos function |
gallery_assist_advanced_help_builder | Provide more Advanced Help functionality for Galley Assist and submodules. |
gallery_assist_api_minimum_version | Information to other GA modules. |
gallery_assist_api_version | Advertise the current GA api version |
gallery_assist_block | Implementation of hook_block(). |
gallery_assist_block_helper | |
gallery_assist_block_t_helper | |
gallery_assist_build_block_item | Build the item box for better css formating. It should be a theme. |
gallery_assist_build_div | |
gallery_assist_build_item_hyperlink | Build gallery items link acording the settings. |
gallery_assist_check_access | |
gallery_assist_check_callback_permission | @TODO: GA: Functionality to check and set the access from GA menus callbacks. |
gallery_assist_check_public_status | Check the gallery public status. |
gallery_assist_check_ur | |
gallery_assist_clearthecache | Clear the Gallery Assist cache table. |
gallery_assist_content_extra_fields | Implementation of hook_content_extra_fields(). |
gallery_assist_cover_updater | Update the cover data by the new and the old cover. |
gallery_assist_delete | Implementation of hook_delete(). |
gallery_assist_delete_directory | Delete the prev and thumbnail dicectories if the node will be deleted. |
gallery_assist_delete_items | Delete all gallery_assist items if the node will be deleted. |
gallery_assist_delete_one | Add to the form the data from the image that will be deleted. Menu callback which is activated by clicking on the link delete over the images. |
gallery_assist_delete_one_submit | Action: delete a image and all entries from the db. |
gallery_assist_display_item | Allow to use jquery effects on the image view such as flash, slideshow, zoom viewer, galleria. |
gallery_assist_display_item_default | Build the output to display each gallery image. Call the own pager and the theme. |
gallery_assist_edit_one | Allow to edit each Gallery Assist Item separately. |
gallery_assist_emulate_pager_pages | Function from ericpai to simulate a multiple pages pager. It calculate all necessary parameters to add pages links to the GA-Pager. |
gallery_assist_file_download | Implementation of hook_file_download. |
gallery_assist_flush_caches | Implementation of hook_flush_caches(). |
gallery_assist_form | Implementation of hook_form(). |
gallery_assist_form_alter | Implementation of hook_form_alter(). |
gallery_assist_form_help_links | |
gallery_assist_form_submit | Prepare some input keys for save. |
gallery_assist_get_assignments | Provide the GA content type assignments. |
gallery_assist_get_includes | Load the needed css- and js-files form submodule lightboxes. |
gallery_assist_get_preset_more_info | name: gallery_assist_get_preset_sizes(). |
gallery_assist_help | Implementation of hook_help(). |
gallery_assist_help_text | TODO: The help should be partitioned acord the different sections (paths). Print the help text for users and administrators. |
gallery_assist_image_more_info | Calculate necessary parameters to build the gallery item boxes. |
gallery_assist_image_prev_more_info | |
gallery_assist_include_display | Display gallery assist container. |
gallery_assist_info_line | This function print the copyright of this module at the back-end interface. |
gallery_assist_init | Implementation of hook_init(). |
gallery_assist_insert | Implementation of hook_insert(). |
gallery_assist_invalidate_cache | Invalidate the gallery_assist cache, forcing a rebuild on the next grab of table data. |
gallery_assist_invoke_myhooktest | Invoke a hook_myhooktest() operation in all modules. |
gallery_assist_item_pager | Build the pager for this module. |
gallery_assist_list_galleries | Gallery list in user profile. A owner see all the own galleries, visitors only the selected to be displayed. |
gallery_assist_list_galleries2 | |
gallery_assist_load | Implementation of hook_load() |
gallery_assist_makedirs | Make the gallery folder and the subfolders for each user with permissions. It is called from hook_load to create the user enviroment (user folder) It is called from the hook_save() by the first uploads (gallery and components: thumbnails, preview, etc). |
gallery_assist_mass_updates | |
gallery_assist_menu | Implementation of hook_menu(). |
gallery_assist_nodeapi | Implementation of hook_nodeapi(). |
gallery_assist_nodetypes_submit | Set default variables for the new assignment and rebuild menus by gallery assist assignment to others content types. |
gallery_assist_node_info | Implementation of hook_node_info(). |
gallery_assist_node_operations | Implementation of hook_node_operations(). |
gallery_assist_panic | Advice administrator in case they delete modules from the drupal installation without using the administration as well. |
gallery_assist_perm | Implementation of hook_perm(). |
gallery_assist_prepare_prev | Render the image item acording needed. |
gallery_assist_prepare_thms | Render the image item acording needed. |
gallery_assist_public_status_updater | Update the public status fron all existing galleries from an assignment. |
gallery_assist_rebuild_alias | |
gallery_assist_rebuild_aliases | |
gallery_assist_recovery | Here are planed the export, rebuild or any other operation. |
gallery_assist_save | Implementation of hook_save(). |
gallery_assist_save_one_js | Save the changes to one item. |
gallery_assist_save_one_submit | |
gallery_assist_settings_submit | Update the settings of gallery_assist or of assignments. |
gallery_assist_set_item_to_cover | Set the gallery cover directly from the gallery page view. |
gallery_assist_sorting_items_standard | |
gallery_assist_standard_sort_submit | |
gallery_assist_theme | Implementation of hook_theme(). |
gallery_assist_token_list | Implementation of hook_token_list(). |
gallery_assist_token_values | Implementation of hook_token_values(). |
gallery_assist_update | Implementation of hook_update(). |
gallery_assist_upload_js | Upload callback over ahah. Prepare the data for save and rebuild the form. |
gallery_assist_users_help | Help for users with create gallery_assist permition. |
theme_gallery_assist_block_display | Theme the block output for the "Gallery Block". the Gallery Block shows a in the proportion minimized Gallery Assist Container. By more as one node setup the block shows galleries randomly. |
theme_gallery_assist_form_current | Theme the item list from the "Add and edit items" form |
theme_gallery_assist_form_new | Theme the "Add and edit items" form. Note: required to output prefix/suffix. |
theme_gallery_assist_item | Theme the output of a singel item. |
theme_gallery_assist_item_submitted | Theme the output from the submited line. Multilingual. |
theme_gallery_assist_pager | Theme the output from the gallery pager. |
theme_gallery_assist_sort_form_current | |
_gallery_assist_block_display | Display the GA-Block Galleries (0). |
_gallery_assist_block_display_1 | Display the GA-Block My Galleries (1). |
_gallery_assist_block_display_2 | Display the GA-Block Gallery Block (2). |
_gallery_assist_block_lgsettings_form | |
_gallery_assist_block_settings_form | Build the GA-Block settings form. |
_gallery_assist_block_settings_form_submit | Save the GA-Block settings. |
_gallery_assist_check_access | Check if user have edit or access permitions and if positiv check the gallery public status. |
_gallery_assist_form | Build the form section for upload- and items-administration. |
_gallery_assist_get_ic_blocksettings_form | Build the select field with the presets list. |
_gallery_assist_lb_includes | Include gallery_assist .js files if not loaded. |
_gallery_assist_mass_updates_batch_finished | |
_gallery_assist_mass_updates_batch_process | |
_gallery_assist_mass_updates_helper | |
_get_ga_form | |
___gallery_assist_list_galleries |