node_gallery.install in Node Gallery 6
Same filename and directory in other branches
Node gallery install file.
File
node_gallery.installView source
<?php
/**
* @file
* Node gallery install file.
*
*/
/**
* Implementation of hook_schema()
*
* @return unknown
*/
function node_gallery_schema() {
$schema = array();
$schema['ng_gallery_config'] = array(
'fields' => array(
'name' => array(
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
),
'gallery_type' => array(
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
),
'image_type' => array(
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
),
'data' => array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
),
),
'primary key' => array(
'gallery_type',
),
);
$schema['ng_images'] = array(
'fields' => array(
'gid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('Gallery node id.'),
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('Image node id.'),
),
'fid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('Image node file id.'),
),
'weight' => array(
'type' => 'int',
'size' => 'small',
'not null' => FALSE,
'default' => 0,
),
'is_cover' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'gallery_image' => array(
'gid',
'nid',
),
),
);
return $schema;
}
/**
* Implementation of hook_install()
*
*/
function node_gallery_install() {
$ret = drupal_install_schema('node_gallery');
_node_gallery_install_type_create();
_node_gallery_install_imagecache_presets();
_node_gallery_set_imagecache_permissions();
_node_gallery_install_default();
}
/**
* Implementation of hook_uninstall()
*
*/
function node_gallery_uninstall() {
$ret = drupal_uninstall_schema('node_gallery');
}
function _node_gallery_install_type_create() {
// During install profiles, node and user modules aren't yet loaded.
// Ensure they're loaded before calling node_get_types().
include_once './' . drupal_get_path('module', 'node') . '/node.module';
include_once './' . drupal_get_path('module', 'user') . '/user.module';
$types = node_get_types();
$types = array_change_key_case($types, CASE_LOWER);
if (!in_array('node_gallery_gallery', array_keys($types))) {
// Create the comment content type.
$node_gallery_node_type = array(
'type' => 'node_gallery_gallery',
'name' => t('Gallery (Node Gallery)'),
'module' => 'node',
'description' => t('This is a gallery (album). This will be the parent of your individual images.'),
'title_label' => t('Gallery Name'),
'body_label' => t('Description'),
'custom' => TRUE,
'modified' => TRUE,
'locked' => FALSE,
);
$node_gallery_node_type = (object) _node_type_set_defaults($node_gallery_node_type);
node_type_save($node_gallery_node_type);
drupal_set_message(t('Node type "Gallery (Node Gallery)" created.'));
}
if (!in_array('node_gallery_image', array_keys($types))) {
// Create the comment content type.
$node_gallery_image_node_type = array(
'type' => 'node_gallery_image',
'name' => t('Gallery Image (Node Gallery)'),
'module' => 'node',
'description' => t('This is an individual image that will be linked to a gallery. This should not be accessed via node/add/node_gallery_image'),
'title_label' => t('Title'),
'body_label' => t('Caption'),
'custom' => TRUE,
'modified' => TRUE,
'locked' => FALSE,
);
$node_gallery_image_node_type = (object) _node_type_set_defaults($node_gallery_image_node_type);
node_type_save($node_gallery_image_node_type);
drupal_set_message(t('Node type "Gallery Image (Node Gallery)" created.'));
}
if (!in_array('node_gallery_gallery', array_keys($types)) || !in_array('node_gallery_image', array_keys($types))) {
cache_clear_all();
system_modules();
menu_rebuild();
node_types_rebuild();
}
}
function _node_gallery_install_default() {
/* Set the defaults for a node_gallery relationship */
$default->name = 'Default Node Gallery';
$default->gallery_type = 'node_gallery_gallery';
$default->image_type = 'node_gallery_image';
$default->data = array(
'display_fields' => array(
'title' => 'title',
'body_field' => 'body_field',
),
'gallery_directory' => '',
'default_cover' => '',
'image_size' => array(
'cover' => 'node-gallery-cover',
'thumbnail' => 'node-gallery-thumbnail',
'preview' => 'node-gallery-display',
),
'teaser' => array(
'gallery_display_type' => 'cover',
'thumbnails_num' => '',
'image' => 'node-gallery-display',
'lightbox2_gallery' => '',
),
'gallery' => array(
'gallery_display' => 'thumbnails',
'lightbox2_gallery_preset' => 'node-gallery-display',
'image' => 'node-gallery-thumbnail',
),
'view_original' => '0',
'view_original_text' => '',
'lightbox2' => 'node-gallery-display',
'content_display' => 'image',
'image_comment' => '2',
'upload_settings' => array(
'number_uploads' => '5',
),
);
$default->data = serialize($default->data);
$sql = "INSERT INTO {ng_gallery_config} VALUES ('%s', '%s', '%s', '%s')";
db_query($sql, $default->name, $default->gallery_type, $default->image_type, $default->data);
}
function _node_gallery_install_imagecache_presets() {
// First, build an array of all the preset names so we do not make duplicates
// Set the argument to TRUE to reset the cache
$presets = imagecache_presets(TRUE);
$preset_names = array();
//If there are any presets
if ($presets != '') {
foreach ($presets as $preset) {
$preset_names[] = $preset['presetname'];
}
}
// Prepare to install ImageCache presets
$imagecache_presets = array();
$imagecache_actions = array();
// We are checking to make sure the preset name does not exist before creating
if (!in_array('node-gallery-thumbnail', $preset_names)) {
$imagecache_presets[] = array(
'presetname' => 'node-gallery-thumbnail',
);
$imagecache_actions['node-gallery-thumbnail'][] = array(
'action' => 'imagecache_scale_and_crop',
'data' => array(
'width' => 100,
'height' => 100,
),
'weight' => 0,
);
}
if (!in_array('node-gallery-cover', $preset_names)) {
$imagecache_presets[] = array(
'presetname' => 'node-gallery-cover',
);
$imagecache_actions['node-gallery-cover'][] = array(
'action' => 'imagecache_scale_and_crop',
'data' => array(
'width' => 150,
'height' => 150,
),
'weight' => 0,
);
}
if (!in_array('node-gallery-display', $preset_names)) {
$imagecache_presets[] = array(
'presetname' => 'node-gallery-display',
);
$imagecache_actions['node-gallery-display'][] = array(
'action' => 'imagecache_scale',
'data' => array(
'height' => 1500,
),
'weight' => 0,
);
$imagecache_actions['node-gallery-display'][] = array(
'action' => 'imagecache_scale',
'data' => array(
'width' => 600,
),
'weight' => 1,
);
}
// Need to install preset, id will be returned by function,
// Then install action add presetid to action prior to install:
foreach ($imagecache_presets as $preset) {
$preset = imagecache_preset_save($preset);
foreach ($imagecache_actions[$preset['presetname']] as $action) {
$action['presetid'] = $preset['presetid'];
imagecache_action_save($action);
}
drupal_set_message(t('ImageCache preset %id: %name and corresponding actions saved.', array(
'%id' => $preset['presetid'],
'%name' => $preset['presetname'],
)));
}
}
function _node_gallery_set_imagecache_permissions() {
$query = db_query("SELECT rid, perm FROM {permission} ORDER BY rid");
while ($role = db_fetch_object($query)) {
$role->perm .= ', view imagecache node-gallery-cover, view imagecache node-gallery-thumbnail, view imagecache node-gallery-display';
update_sql("UPDATE {permission} SET perm = '{$role->perm}' WHERE rid = {$role->rid}");
}
}
/**
* Implementation of hook_update_N()
* Directly installing the default imagecache presets
*/
function node_gallery_update_6100() {
$ret = array();
_node_gallery_install_imagecache_presets();
_node_gallery_set_imagecache_permissions();
return $ret;
}
/**
* Implementation of hook_update_N()
* Updating the database for the changing options for "view original"
*/
function node_gallery_update_6101() {
$ret = array();
$result = db_query("SELECT * FROM {ng_gallery_config} WHERE 1");
$t = drupal_unpack(db_fetch_object($result));
while ($t = drupal_unpack(db_fetch_object($result))) {
if (!empty($t)) {
$relationship = new gallery_config($t);
if (!$relationship->lightbox2) {
$relationship->lightbox2 = 'node-gallery-display';
}
if (!$relationship->view_original_text) {
$relationship->view_original_text = '';
}
if ($relationship->view_original == '1') {
$relationship->view_original = 'default';
}
unset($relationship->data);
$relationship
->save();
}
}
return $ret;
}
/**
* Implementation of hook_update_N()
* Updating the database for the changing options for "view teaser"
*/
function node_gallery_update_6102() {
$ret = array();
$result = db_query("SELECT * FROM {ng_gallery_config} WHERE 1");
while ($t = drupal_unpack(db_fetch_object($result))) {
if (!empty($t)) {
$relationship = new gallery_config($t);
if ($relationship->teaser['gallery_display_type'] == '0') {
$relationship->teaser['gallery_display_type'] = 'cover';
}
elseif ($relationship->teaser['gallery_display_type'] == '1') {
$relationship->teaser['gallery_display_type'] = 'thumbnails';
}
$relationship->gallery = array(
'gallery_display' => 'thumbnails',
'lightbox2_gallery_preset' => 'node-gallery-display',
);
unset($relationship->data);
$relationship
->save();
}
}
return $ret;
}
/**
* Implementation of hook_update_N()
* Updating the database so we can custom select the number of uploads
*/
function node_gallery_update_6103() {
$ret = array();
$result = db_query("SELECT * FROM {ng_gallery_config} WHERE 1");
while ($t = drupal_unpack(db_fetch_object($result))) {
if (!empty($t)) {
$relationship = new gallery_config($t);
$relationship->upload_settings = array(
'number_uploads' => '5',
);
unset($relationship->data);
$relationship
->save();
}
}
return $ret;
}
/**
* Implementation of hook_update_N()
* A gallery display type
*/
function node_gallery_update_6104() {
$ret = array();
$result = db_query("SELECT * FROM {ng_gallery_config} WHERE 1");
while ($t = drupal_unpack(db_fetch_object($result))) {
if (!empty($t)) {
$relationship = new gallery_config($t);
$relationship->gallery['image'] = 'node-gallery-thumbnail';
unset($relationship->data);
$relationship
->save();
}
}
return $ret;
}
Functions
Name | Description |
---|---|
node_gallery_install | Implementation of hook_install() |
node_gallery_schema | Implementation of hook_schema() |
node_gallery_uninstall | Implementation of hook_uninstall() |
node_gallery_update_6100 | Implementation of hook_update_N() Directly installing the default imagecache presets |
node_gallery_update_6101 | Implementation of hook_update_N() Updating the database for the changing options for "view original" |
node_gallery_update_6102 | Implementation of hook_update_N() Updating the database for the changing options for "view teaser" |
node_gallery_update_6103 | Implementation of hook_update_N() Updating the database so we can custom select the number of uploads |
node_gallery_update_6104 | Implementation of hook_update_N() A gallery display type |
_node_gallery_install_default | |
_node_gallery_install_imagecache_presets | |
_node_gallery_install_type_create | |
_node_gallery_set_imagecache_permissions |