| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* $Id: $
|
| 4 |
* @package OG_CTA
|
| 5 |
* @category NeighborForge
|
| 6 |
*/
|
| 7 |
|
| 8 |
/**
|
| 9 |
* Constants to indicate whether a content type is assigned to a group.
|
| 10 |
*/
|
| 11 |
define('NOT_ASSIGNED_TO_GROUP', 0);
|
| 12 |
define('ASSIGNED_TO_GROUP', 1);
|
| 13 |
|
| 14 |
/**
|
| 15 |
* Constants to indicate whether a content type is activated/deactivated/required.
|
| 16 |
*/
|
| 17 |
define('DEACTIVATED', 0);
|
| 18 |
define('ACTIVATED', 1);
|
| 19 |
define('REQUIRED', 2);
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
/**
|
| 24 |
* Implementation of hook_schema().
|
| 25 |
*/
|
| 26 |
function og_content_type_admin_schema() {
|
| 27 |
$schema['og_content_type_admin'] = array(
|
| 28 |
'fields' => array(
|
| 29 |
'gid' => array('type' => 'int', 'length' => '11', 'not null' => TRUE, 'default' => '0'),
|
| 30 |
'name' => array('type' => 'varchar', 'length' => '128', 'not null' => TRUE, 'default' => ''),
|
| 31 |
'types_allowed' => array('type' => 'text', 'size' => 'big', 'not null' => TRUE),
|
| 32 |
'types_active' => array('type' => 'text', 'size' => 'big', 'not null' => TRUE),
|
| 33 |
|
| 34 |
),
|
| 35 |
'primary key' => array('gid')
|
| 36 |
);
|
| 37 |
return $schema;
|
| 38 |
}
|
| 39 |
|
| 40 |
|
| 41 |
/**
|
| 42 |
* Implementation of hook_install().
|
| 43 |
*/
|
| 44 |
function og_content_type_admin_install() {
|
| 45 |
// Create tables.
|
| 46 |
drupal_install_schema('og_content_type_admin');
|
| 47 |
|
| 48 |
$query2 = db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", 3, 'og_content_type_admin');
|
| 49 |
|
| 50 |
//now that the tables are created, create rows for the site-wide and group default settings
|
| 51 |
$node_types = node_get_types();
|
| 52 |
foreach ($node_types as $type) {
|
| 53 |
$all_allowed[$type->type] = ASSIGNED_TO_GROUP;
|
| 54 |
$all_active[$type->type] = REQUIRED;
|
| 55 |
}
|
| 56 |
$og_node_types = variable_get('og_node_types', array('og'));
|
| 57 |
$og_omitted = variable_get('og_omitted', array());
|
| 58 |
$exempt = array_merge($og_node_types, $og_omitted);
|
| 59 |
$swgid = -1;
|
| 60 |
$sitewide = 'Site Wide';
|
| 61 |
$query3 = db_query("INSERT INTO {og_content_type_admin} (gid, name, types_allowed, types_active) VALUES (%d, '%s', '%s', '%s')", $swgid, $sitewide, serialize($all_allowed), serialize($all_active));
|
| 62 |
foreach ($node_types as $type) {
|
| 63 |
if (!in_array($type->type, $exempt)) {
|
| 64 |
$group_allowed[$type->type] = ASSIGNED_TO_GROUP;
|
| 65 |
$group_active[$type->type] = ACTIVATED;
|
| 66 |
}
|
| 67 |
}
|
| 68 |
$dfgid = 0;
|
| 69 |
$group_default = 'Default';
|
| 70 |
$query4 = db_query("INSERT INTO {og_content_type_admin} (gid, name, types_allowed, types_active) VALUES (%d, '%s', '%s', '%s')", $dfgid, $group_default, serialize($group_allowed), serialize($group_active));
|
| 71 |
|
| 72 |
//make sure all went well
|
| 73 |
if ($query2 && $query3 && $query4) {
|
| 74 |
drupal_set_message('The OG Content Type Admin module was installed successfully. A table was added to the database.');
|
| 75 |
}
|
| 76 |
else {
|
| 77 |
drupal_set_message('There was an error installing the OG Content Type Admin database table.', 'error');
|
| 78 |
}
|
| 79 |
|
| 80 |
}
|
| 81 |
|
| 82 |
/**
|
| 83 |
* Implementation of hook_enable
|
| 84 |
*
|
| 85 |
* We need to disable the regular OG block in favor of the new one.
|
| 86 |
*/
|
| 87 |
function og_content_type_admin_enable() {
|
| 88 |
//replace the og block called og_block_detail with our own
|
| 89 |
$og_module = 'og';
|
| 90 |
$og_delta = 0;
|
| 91 |
$query5abad = 1;
|
| 92 |
$query6bad = 1;
|
| 93 |
$query7bad = 1;
|
| 94 |
$query5 = db_query("SELECT * FROM {blocks} b WHERE b.module = '%s' AND b.delta = %d", $og_module, $og_delta);
|
| 95 |
while ($block_data = db_fetch_object($query5)) {
|
| 96 |
$query5a = db_query("UPDATE {blocks} SET status = %d, region = '%s' WHERE module = '%s' AND delta = %d", 0, '', $og_module, $og_delta);
|
| 97 |
if (!$query5) {
|
| 98 |
$query5abad = 0;
|
| 99 |
}
|
| 100 |
$this_module = 'og_content_type_admin';
|
| 101 |
$query6 = db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, custom, throttle, visibility)
|
| 102 |
VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, %d, %d)",
|
| 103 |
$this_module, $block_data->delta, $block_data->theme, $block_data->status, $block_data->weight, $block_data->region, $block_data->custom, $block_data->throttle, $block_data->visibility);
|
| 104 |
if (!$query6) {
|
| 105 |
$query6bad = 0;
|
| 106 |
}
|
| 107 |
}
|
| 108 |
//now change the title of the node/add menu item to indicate a little better that there is a division between group and site-wide content
|
| 109 |
$path = 'node/add';
|
| 110 |
$new_title = 'Create general content';
|
| 111 |
$query7 = db_query("UPDATE {menu_links} SET link_title = '%s' WHERE link_path = '%s'", $new_title, $path);
|
| 112 |
if (!$query7) {
|
| 113 |
$query7bad = 0;
|
| 114 |
}
|
| 115 |
if ($query5 && $query5abad && $query6bad && $query7bad) {
|
| 116 |
drupal_set_message('The OG Content Type Admin module was enabled successfully. Default settings were initialized.');
|
| 117 |
}
|
| 118 |
else {
|
| 119 |
drupal_set_message('There was an error setting the OG Content Type Admin settings.', 'error');
|
| 120 |
}
|
| 121 |
}
|
| 122 |
|
| 123 |
/**
|
| 124 |
* Implementation of hook_uninstall().
|
| 125 |
*/
|
| 126 |
function og_content_type_admin_uninstall() {
|
| 127 |
drupal_uninstall_schema('og_content_type_admin');
|
| 128 |
drupal_set_message('The OG Content Type Admin module was uninstalled successfully.');
|
| 129 |
}
|
| 130 |
|
| 131 |
function og_content_type_admin_disable() {
|
| 132 |
//restore the og block called og_block_detail with the data ours is now using
|
| 133 |
$this_module = 'og_content_type_admin';
|
| 134 |
$this_delta = 0;
|
| 135 |
$query2 = db_query("SELECT * FROM {blocks} b WHERE b.module = '%s' AND b.delta = %d", $this_module, $this_delta);
|
| 136 |
while ($block_data = db_fetch_object($query2)) {
|
| 137 |
$og_module = 'og';
|
| 138 |
$query3 = db_query("UPDATE {blocks} SET status = %d, weight = %d, region = '%s', custom = %d, throttle = %d, visibility = %d WHERE module = '%s' AND delta = %d",
|
| 139 |
$block_data->theme, $block_data->status, $block_data->weight, $block_data->region, $block_data->custom, $block_data->throttle, $block_data->visibility, $og_module, $this_delta);
|
| 140 |
}
|
| 141 |
//now that it's restored, remove ours
|
| 142 |
$query4 = db_query("DELETE FROM {blocks} WHERE module = '%s'", $this_module);
|
| 143 |
|
| 144 |
//now change the title of the node/add menu item back to its original name
|
| 145 |
$path = 'node/add';
|
| 146 |
$old_title = 'Create content';
|
| 147 |
$query5 = db_query("UPDATE {menu_links} SET link_title = '%s' WHERE link_path = '%s'", $old_title, $path);
|
| 148 |
if ($query2 && $query3 && $query4 && $query5) {
|
| 149 |
drupal_set_message('The OG Content Type Admin module was disabled successfully.');
|
| 150 |
}
|
| 151 |
else {
|
| 152 |
drupal_set_message('There was an error restoring the original OG block settings.', 'error');
|
| 153 |
}
|
| 154 |
}
|