| 1 |
<?php
|
| 2 |
// $Id: node_gallery.install,v 1.14 2009/04/27 19:22:29 kmonty Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Node gallery install file.
|
| 7 |
*
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_schema()
|
| 12 |
*
|
| 13 |
* @return unknown
|
| 14 |
*/
|
| 15 |
function node_gallery_schema() {
|
| 16 |
$schema = array();
|
| 17 |
|
| 18 |
$schema['ng_gallery_config'] = array(
|
| 19 |
'fields' => array(
|
| 20 |
'name' => array(
|
| 21 |
'type' => 'varchar',
|
| 22 |
'length' => '32',
|
| 23 |
'not null' => TRUE,
|
| 24 |
'default' => ''
|
| 25 |
),
|
| 26 |
'gallery_type' => array(
|
| 27 |
'type' => 'varchar',
|
| 28 |
'length' => '32',
|
| 29 |
'not null' => TRUE,
|
| 30 |
'default' => ''
|
| 31 |
),
|
| 32 |
'image_type' => array(
|
| 33 |
'type' => 'varchar',
|
| 34 |
'length' => '32',
|
| 35 |
'not null' => TRUE,
|
| 36 |
'default' => ''
|
| 37 |
),
|
| 38 |
'data' => array(
|
| 39 |
'type' => 'text',
|
| 40 |
'not null' => FALSE,
|
| 41 |
'size' => 'big',
|
| 42 |
),
|
| 43 |
),
|
| 44 |
'primary key' => array('gallery_type'),
|
| 45 |
);
|
| 46 |
|
| 47 |
$schema['ng_images'] = array(
|
| 48 |
'fields' => array(
|
| 49 |
'gid' => array(
|
| 50 |
'type' => 'int',
|
| 51 |
'unsigned' => TRUE,
|
| 52 |
'not null' => TRUE,
|
| 53 |
'default' => 0,
|
| 54 |
'description' => t('Gallery node id.'),
|
| 55 |
),
|
| 56 |
'nid' => array(
|
| 57 |
'type' => 'int',
|
| 58 |
'unsigned' => TRUE,
|
| 59 |
'not null' => TRUE,
|
| 60 |
'default' => 0,
|
| 61 |
'description' => t('Image node id.'),
|
| 62 |
),
|
| 63 |
'fid' => array(
|
| 64 |
'type' => 'int',
|
| 65 |
'unsigned' => TRUE,
|
| 66 |
'not null' => TRUE,
|
| 67 |
'default' => 0,
|
| 68 |
'description' => t('Image node file id.'),
|
| 69 |
),
|
| 70 |
'weight' => array(
|
| 71 |
'type' => 'int',
|
| 72 |
'size' => 'small',
|
| 73 |
'not null' => FALSE,
|
| 74 |
'default' => 0,
|
| 75 |
),
|
| 76 |
'is_cover' => array(
|
| 77 |
'type' => 'int',
|
| 78 |
'size' => 'tiny',
|
| 79 |
'not null' => TRUE,
|
| 80 |
'default' => 0,
|
| 81 |
),
|
| 82 |
),
|
| 83 |
'indexes' => array(
|
| 84 |
'gallery_image' => array('gid', 'nid'),
|
| 85 |
),
|
| 86 |
);
|
| 87 |
|
| 88 |
return $schema;
|
| 89 |
}
|
| 90 |
|
| 91 |
/**
|
| 92 |
* Implementation of hook_install()
|
| 93 |
*
|
| 94 |
*/
|
| 95 |
function node_gallery_install() {
|
| 96 |
$ret = drupal_install_schema('node_gallery');
|
| 97 |
_node_gallery_install_type_create();
|
| 98 |
_node_gallery_install_imagecache_presets();
|
| 99 |
_node_gallery_set_imagecache_permissions();
|
| 100 |
_node_gallery_install_default();
|
| 101 |
}
|
| 102 |
|
| 103 |
/**
|
| 104 |
* Implementation of hook_uninstall()
|
| 105 |
*
|
| 106 |
*/
|
| 107 |
function node_gallery_uninstall() {
|
| 108 |
$ret = drupal_uninstall_schema('node_gallery');
|
| 109 |
}
|
| 110 |
|
| 111 |
function _node_gallery_install_type_create() {
|
| 112 |
// During install profiles, node and user modules aren't yet loaded.
|
| 113 |
// Ensure they're loaded before calling node_get_types().
|
| 114 |
include_once './'. drupal_get_path('module', 'node') .'/node.module';
|
| 115 |
include_once './'. drupal_get_path('module', 'user') .'/user.module';
|
| 116 |
$types = node_get_types();
|
| 117 |
$types = array_change_key_case($types, CASE_LOWER);
|
| 118 |
|
| 119 |
if (!in_array('node_gallery_gallery', array_keys($types))) {
|
| 120 |
// Create the comment content type.
|
| 121 |
$node_gallery_node_type = array(
|
| 122 |
'type' => 'node_gallery_gallery',
|
| 123 |
'name' => t('Gallery (Node Gallery)'),
|
| 124 |
'module' => 'node',
|
| 125 |
'description' => t('This is a gallery (album). This will be the parent of your individual images.'),
|
| 126 |
'title_label' => t('Gallery Name'),
|
| 127 |
'body_label' => t('Description'),
|
| 128 |
'custom' => TRUE,
|
| 129 |
'modified' => TRUE,
|
| 130 |
'locked' => FALSE,
|
| 131 |
);
|
| 132 |
$node_gallery_node_type = (object)_node_type_set_defaults($node_gallery_node_type);
|
| 133 |
node_type_save($node_gallery_node_type);
|
| 134 |
drupal_set_message(t('Node type "Gallery (Node Gallery)" created.'));
|
| 135 |
}
|
| 136 |
if (!in_array('node_gallery_image', array_keys($types))) {
|
| 137 |
// Create the comment content type.
|
| 138 |
$node_gallery_image_node_type = array(
|
| 139 |
'type' => 'node_gallery_image',
|
| 140 |
'name' => t('Gallery Image (Node Gallery)'),
|
| 141 |
'module' => 'node',
|
| 142 |
'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'),
|
| 143 |
'title_label' => t('Title'),
|
| 144 |
'body_label' => t('Caption'),
|
| 145 |
'custom' => TRUE,
|
| 146 |
'modified' => TRUE,
|
| 147 |
'locked' => FALSE,
|
| 148 |
);
|
| 149 |
$node_gallery_image_node_type = (object)_node_type_set_defaults($node_gallery_image_node_type);
|
| 150 |
node_type_save($node_gallery_image_node_type);
|
| 151 |
drupal_set_message(t('Node type "Gallery Image (Node Gallery)" created.'));
|
| 152 |
}
|
| 153 |
if (!in_array('node_gallery_gallery', array_keys($types)) || !in_array('node_gallery_image', array_keys($types))) {
|
| 154 |
cache_clear_all();
|
| 155 |
system_modules();
|
| 156 |
menu_rebuild();
|
| 157 |
node_types_rebuild();
|
| 158 |
}
|
| 159 |
}
|
| 160 |
|
| 161 |
function _node_gallery_install_default() {
|
| 162 |
/* Set the defaults for a node_gallery relationship */
|
| 163 |
$default->name = 'Default Node Gallery';
|
| 164 |
$default->gallery_type = 'node_gallery_gallery';
|
| 165 |
$default->image_type = 'node_gallery_image';
|
| 166 |
$default->data = array(
|
| 167 |
'display_fields' => array(
|
| 168 |
'title' => 'title',
|
| 169 |
'body_field' => 'body_field',
|
| 170 |
),
|
| 171 |
'gallery_directory' => '',
|
| 172 |
'default_cover' => '',
|
| 173 |
'image_size' => array(
|
| 174 |
'cover' => 'node-gallery-cover',
|
| 175 |
'thumbnail' => 'node-gallery-thumbnail',
|
| 176 |
'preview' => 'node-gallery-display',
|
| 177 |
),
|
| 178 |
'teaser' => array(
|
| 179 |
'gallery_display_type' => 'cover',
|
| 180 |
'thumbnails_num' => '',
|
| 181 |
'image' => 'node-gallery-display',
|
| 182 |
'lightbox2_gallery' => '',
|
| 183 |
),
|
| 184 |
'gallery' => array(
|
| 185 |
'gallery_display' => 'thumbnails',
|
| 186 |
'lightbox2_gallery_preset' => 'node-gallery-display',
|
| 187 |
'image' => 'node-gallery-thumbnail',
|
| 188 |
),
|
| 189 |
'view_original' => '0',
|
| 190 |
'view_original_text' => '',
|
| 191 |
'lightbox2' => 'node-gallery-display',
|
| 192 |
'content_display' => 'image',
|
| 193 |
'image_comment' => '2',
|
| 194 |
'upload_settings' => array(
|
| 195 |
'number_uploads' => '5',
|
| 196 |
),
|
| 197 |
);
|
| 198 |
|
| 199 |
$default->data = serialize($default->data);
|
| 200 |
|
| 201 |
$sql = "INSERT INTO {ng_gallery_config} VALUES ('%s', '%s', '%s', '%s')";
|
| 202 |
db_query($sql, $default->name, $default->gallery_type, $default->image_type, $default->data);
|
| 203 |
}
|
| 204 |
|
| 205 |
function _node_gallery_install_imagecache_presets() {
|
| 206 |
// First, build an array of all the preset names so we do not make duplicates
|
| 207 |
// Set the argument to TRUE to reset the cache
|
| 208 |
$presets = imagecache_presets(TRUE);
|
| 209 |
$preset_names = array();
|
| 210 |
|
| 211 |
//If there are any presets
|
| 212 |
if ($presets != '') {
|
| 213 |
foreach ($presets as $preset) {
|
| 214 |
$preset_names[] = $preset['presetname'];
|
| 215 |
}
|
| 216 |
}
|
| 217 |
|
| 218 |
|
| 219 |
// Prepare to install ImageCache presets
|
| 220 |
$imagecache_presets = array();
|
| 221 |
$imagecache_actions = array();
|
| 222 |
|
| 223 |
// We are checking to make sure the preset name does not exist before creating
|
| 224 |
if (!in_array('node-gallery-thumbnail', $preset_names)) {
|
| 225 |
$imagecache_presets[] = array(
|
| 226 |
'presetname' => 'node-gallery-thumbnail',
|
| 227 |
);
|
| 228 |
$imagecache_actions['node-gallery-thumbnail'][] = array(
|
| 229 |
'action' => 'imagecache_scale_and_crop',
|
| 230 |
'data' => array(
|
| 231 |
'width' => 100,
|
| 232 |
'height' => 100,
|
| 233 |
),
|
| 234 |
'weight' => 0,
|
| 235 |
);
|
| 236 |
}
|
| 237 |
|
| 238 |
if (!in_array('node-gallery-cover', $preset_names)) {
|
| 239 |
$imagecache_presets[] = array(
|
| 240 |
'presetname' => 'node-gallery-cover',
|
| 241 |
);
|
| 242 |
$imagecache_actions['node-gallery-cover'][] = array(
|
| 243 |
'action' => 'imagecache_scale_and_crop',
|
| 244 |
'data' => array(
|
| 245 |
'width' => 150,
|
| 246 |
'height' => 150,
|
| 247 |
),
|
| 248 |
'weight' => 0,
|
| 249 |
);
|
| 250 |
}
|
| 251 |
|
| 252 |
if (!in_array('node-gallery-display', $preset_names)) {
|
| 253 |
$imagecache_presets[] = array(
|
| 254 |
'presetname' => 'node-gallery-display',
|
| 255 |
);
|
| 256 |
$imagecache_actions['node-gallery-display'][] = array(
|
| 257 |
'action' => 'imagecache_scale',
|
| 258 |
'data' => array(
|
| 259 |
'height' => 1500,
|
| 260 |
),
|
| 261 |
'weight' => 0,
|
| 262 |
);
|
| 263 |
$imagecache_actions['node-gallery-display'][] = array(
|
| 264 |
'action' => 'imagecache_scale',
|
| 265 |
'data' => array(
|
| 266 |
'width' => 600,
|
| 267 |
),
|
| 268 |
'weight' => 1,
|
| 269 |
);
|
| 270 |
}
|
| 271 |
|
| 272 |
// Need to install preset, id will be returned by function,
|
| 273 |
// Then install action add presetid to action prior to install:
|
| 274 |
foreach ($imagecache_presets as $preset) {
|
| 275 |
$preset = imagecache_preset_save($preset);
|
| 276 |
foreach ($imagecache_actions[$preset['presetname']] as $action) {
|
| 277 |
$action['presetid'] = $preset['presetid'];
|
| 278 |
imagecache_action_save($action);
|
| 279 |
}
|
| 280 |
drupal_set_message(t('ImageCache preset %id: %name and corresponding actions saved.', array('%id' => $preset['presetid'], '%name' => $preset['presetname'])));
|
| 281 |
}
|
| 282 |
}
|
| 283 |
|
| 284 |
function _node_gallery_set_imagecache_permissions() {
|
| 285 |
$query = db_query("SELECT rid, perm FROM {permission} ORDER BY rid");
|
| 286 |
while ($role = db_fetch_object($query)) {
|
| 287 |
$role->perm .= ', view imagecache node-gallery-cover, view imagecache node-gallery-thumbnail, view imagecache node-gallery-display';
|
| 288 |
update_sql("UPDATE {permission} SET perm = '$role->perm' WHERE rid = $role->rid");
|
| 289 |
}
|
| 290 |
}
|
| 291 |
|
| 292 |
/**
|
| 293 |
* Implementation of hook_update_N()
|
| 294 |
* Directly installing the default imagecache presets
|
| 295 |
*/
|
| 296 |
function node_gallery_update_6100() {
|
| 297 |
$ret = array();
|
| 298 |
_node_gallery_install_imagecache_presets();
|
| 299 |
_node_gallery_set_imagecache_permissions();
|
| 300 |
return $ret;
|
| 301 |
}
|
| 302 |
|
| 303 |
/**
|
| 304 |
* Implementation of hook_update_N()
|
| 305 |
* Updating the database for the changing options for "view original"
|
| 306 |
*/
|
| 307 |
function node_gallery_update_6101() {
|
| 308 |
$ret = array();
|
| 309 |
$result = db_query("SELECT * FROM {ng_gallery_config} WHERE 1");
|
| 310 |
$t = drupal_unpack(db_fetch_object($result));
|
| 311 |
while ($t = drupal_unpack(db_fetch_object($result))) {
|
| 312 |
if (!empty($t)) {
|
| 313 |
$relationship = new gallery_config($t);
|
| 314 |
if (!$relationship->lightbox2) {
|
| 315 |
$relationship->lightbox2 = 'node-gallery-display';
|
| 316 |
}
|
| 317 |
if (!$relationship->view_original_text) {
|
| 318 |
$relationship->view_original_text = '';
|
| 319 |
}
|
| 320 |
if ($relationship->view_original == '1') {
|
| 321 |
$relationship->view_original = 'default';
|
| 322 |
}
|
| 323 |
unset($relationship->data);
|
| 324 |
|
| 325 |
$relationship->save();
|
| 326 |
}
|
| 327 |
}
|
| 328 |
return $ret;
|
| 329 |
}
|
| 330 |
|
| 331 |
/**
|
| 332 |
* Implementation of hook_update_N()
|
| 333 |
* Updating the database for the changing options for "view teaser"
|
| 334 |
*/
|
| 335 |
function node_gallery_update_6102() {
|
| 336 |
$ret = array();
|
| 337 |
$result = db_query("SELECT * FROM {ng_gallery_config} WHERE 1");
|
| 338 |
while ($t = drupal_unpack(db_fetch_object($result))) {
|
| 339 |
if (!empty($t)) {
|
| 340 |
$relationship = new gallery_config($t);
|
| 341 |
if ($relationship->teaser['gallery_display_type'] == '0') {
|
| 342 |
$relationship->teaser['gallery_display_type'] = 'cover';
|
| 343 |
}
|
| 344 |
elseif ($relationship->teaser['gallery_display_type'] == '1') {
|
| 345 |
$relationship->teaser['gallery_display_type'] = 'thumbnails';
|
| 346 |
}
|
| 347 |
$relationship->gallery = array(
|
| 348 |
'gallery_display' => 'thumbnails',
|
| 349 |
'lightbox2_gallery_preset' => 'node-gallery-display',
|
| 350 |
);
|
| 351 |
unset($relationship->data);
|
| 352 |
$relationship->save();
|
| 353 |
}
|
| 354 |
}
|
| 355 |
return $ret;
|
| 356 |
}
|
| 357 |
|
| 358 |
/**
|
| 359 |
* Implementation of hook_update_N()
|
| 360 |
* Updating the database so we can custom select the number of uploads
|
| 361 |
*/
|
| 362 |
function node_gallery_update_6103() {
|
| 363 |
$ret = array();
|
| 364 |
$result = db_query("SELECT * FROM {ng_gallery_config} WHERE 1");
|
| 365 |
while ($t = drupal_unpack(db_fetch_object($result))) {
|
| 366 |
if (!empty($t)) {
|
| 367 |
$relationship = new gallery_config($t);
|
| 368 |
$relationship->upload_settings = array(
|
| 369 |
'number_uploads' => '5',
|
| 370 |
);
|
| 371 |
unset($relationship->data);
|
| 372 |
$relationship->save();
|
| 373 |
}
|
| 374 |
}
|
| 375 |
return $ret;
|
| 376 |
}
|
| 377 |
|
| 378 |
/**
|
| 379 |
* Implementation of hook_update_N()
|
| 380 |
* A gallery display type
|
| 381 |
*/
|
| 382 |
function node_gallery_update_6104() {
|
| 383 |
$ret = array();
|
| 384 |
$result = db_query("SELECT * FROM {ng_gallery_config} WHERE 1");
|
| 385 |
while ($t = drupal_unpack(db_fetch_object($result))) {
|
| 386 |
if (!empty($t)) {
|
| 387 |
$relationship = new gallery_config($t);
|
| 388 |
$relationship->gallery['image'] = 'node-gallery-thumbnail';
|
| 389 |
unset($relationship->data);
|
| 390 |
$relationship->save();
|
| 391 |
}
|
| 392 |
}
|
| 393 |
return $ret;
|
| 394 |
}
|