| 16 |
* were marked as 'required' by the site admin will always be usable by the group members and |
* were marked as 'required' by the site admin will always be usable by the group members and |
| 17 |
* cannot be deactivated by the group owner.</p> |
* cannot be deactivated by the group owner.</p> |
| 18 |
* |
* |
| 19 |
* @version $Id: og_content_type_admin.module,v 1.15.2.8 2009/01/21 15:45:32 paulbooker Exp $; |
* @version $Id: og_content_type_admin.module,v 1.15.2.9 2009/02/02 15:29:22 paulbooker Exp $; |
| 20 |
* @package OG_CTA |
* @package OG_CTA |
| 21 |
* @category NeighborForge |
* @category NeighborForge |
| 22 |
* @author Ryan Constantine |
* @author Ryan Constantine |
| 68 |
} // function og_content_type_admin_help() |
} // function og_content_type_admin_help() |
| 69 |
|
|
| 70 |
/** |
/** |
|
* Implementation of hook_init(). |
|
|
*/ |
|
|
function og_content_type_admin_init() { |
|
|
menu_router_build(TRUE); |
|
|
node_types_rebuild(); |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
| 71 |
* Implementation of hook_perm |
* Implementation of hook_perm |
| 72 |
* |
* |
| 73 |
* Valid permissions for this module |
* Valid permissions for this module |
| 237 |
$form_values = $form_state['values']; |
$form_values = $form_state['values']; |
| 238 |
if ($form_values['op'] == t('Add group')) { |
if ($form_values['op'] == t('Add group')) { |
| 239 |
$all_groups = og_all_groups_options(); |
$all_groups = og_all_groups_options(); |
| 240 |
db_query("INSERT INTO {og_content_type_admin} (gid, name) VALUES (%d, '%s')", $form_values['group'], $all_groups[$form_values['group']]); |
db_query("INSERT INTO {og_content_type_admin} (gid, name, types_allowed, types_active) VALUES (%d, '%s', '', '')", $form_values['group'], $all_groups[$form_values['group']]); |
| 241 |
drupal_set_message(t('The group has been added.')); |
drupal_set_message(t('The group has been added.')); |
| 242 |
} |
} |
| 243 |
$form_state['redirect'] = 'admin/og/og_content_types'; |
$form_state['redirect'] = 'admin/og/og_content_types'; |
| 749 |
*/ |
*/ |
| 750 |
function og_content_type_admin_menu_alter(&$callbacks) { |
function og_content_type_admin_menu_alter(&$callbacks) { |
| 751 |
global $user; |
global $user; |
| 752 |
$post_type = arg(2); |
// First: Replace access callback to all content types and handle all create content pages. |
|
// First: Deny access to all content types and handle all create content pages. |
|
| 753 |
$types = node_get_types(); |
$types = node_get_types(); |
| 754 |
foreach ($types as $type) { |
foreach ($types as $type) { |
| 755 |
$type = $type->type; |
$type = $type->type; |
| 756 |
$node_type = isset($type) ? str_replace('_', '-', $type) : NULL; |
$node_type = isset($type) ? str_replace('_', '-', $type) : NULL; |
| 757 |
$type_path = "node/add/$node_type"; |
$type_path = "node/add/$node_type"; |
| 758 |
$callbacks[$type_path]['access callback'] = FALSE; |
$old_callback = $callbacks[$type_path]['access callback']; |
| 759 |
|
$old_args = $callbacks[$type_path]['access arguments']; |
| 760 |
|
array_unshift($old_args, $old_callback); |
| 761 |
|
array_unshift($old_args, 2); // we need to get node type for our own processing |
| 762 |
|
$callbacks[$type_path]['access callback'] = 'og_content_type_admin_menu_access'; |
| 763 |
|
$callbacks[$type_path]['access arguments'] = $old_args; // pass original callback and its arguments as parameters |
| 764 |
$callbacks[$type_path]['page callback'] = 'og_content_type_admin_node_add'; |
$callbacks[$type_path]['page callback'] = 'og_content_type_admin_node_add'; |
| 765 |
} |
} |
| 766 |
/*TODO: Would something like the below work above ? |
/*TODO: Would something like the below work above ? |
| 768 |
*$callbacks[]['page callback'] = 'og_content_type_admin_node_add'; |
*$callbacks[]['page callback'] = 'og_content_type_admin_node_add'; |
| 769 |
*/ |
*/ |
| 770 |
$callbacks['node/add']['page callback'] = 'og_content_type_admin_node_add'; |
$callbacks['node/add']['page callback'] = 'og_content_type_admin_node_add'; |
| 771 |
// Second: Allow access to add a particlar type of group content |
} |
| 772 |
if (is_array($_GET[gids])) { |
|
| 773 |
$gid = $_GET[gids][0]; |
/** |
| 774 |
|
* mnode/add access callback override. If gid is present check og_content_type access rights. Otherwise pass processing to original function |
| 775 |
|
*/ |
| 776 |
|
function og_content_type_admin_menu_access() { |
| 777 |
|
$args = func_get_args(); |
| 778 |
|
$type = array_shift($args); |
| 779 |
|
$type = isset($type) ? str_replace('-', '_', $type) : NULL; |
| 780 |
|
$original_callback = array_shift($args); |
| 781 |
|
|
| 782 |
|
// First: Allow access to add a particlar type of group content |
| 783 |
|
if (is_array($_GET['gids'])) { |
| 784 |
|
$gid = $_GET['gids'][0]; |
| 785 |
$sql = "SELECT octa.types_active, octa.types_allowed FROM {og_content_type_admin} octa WHERE octa.gid = %d"; |
$sql = "SELECT octa.types_active, octa.types_allowed FROM {og_content_type_admin} octa WHERE octa.gid = %d"; |
| 786 |
//if we're keeping track of this group, get it's active types, otherwise, get the defaults |
//if we're keeping track of this group, get it's active types, otherwise, get the defaults |
| 787 |
$types = db_fetch_object(db_query($sql, $node->nid)); // TODO: Should this be $gid ? |
$types = db_fetch_object(db_query($sql, $gid)); // TODO: Should this be $gid ? |
| 788 |
if (!count($types->types_active)) { |
if (!$types) { |
| 789 |
$types = db_fetch_object(db_query($sql, 0)); |
$types = db_fetch_object(db_query($sql, 0)); |
| 790 |
} |
} |
| 791 |
$activated_types = unserialize($types->types_active); |
$active_types = unserialize($types->types_active); |
| 792 |
foreach ($activated_types as $type => $value) { |
if ($active_types[$type]) { |
| 793 |
$node_type = isset($type) ? str_replace('_', '-', $type) : NULL; |
return TRUE; |
| 794 |
if ($node_type == $post_type) { |
} |
| 795 |
$type_path = "node/add/$node_type"; |
} |
| 796 |
$callbacks[$type_path]['access callback'] = TRUE; |
else { // do normal processing plus 'allowed' check |
| 797 |
} |
$sql = "SELECT octa.types_allowed FROM {og_content_type_admin} octa WHERE octa.gid = -1"; |
| 798 |
} |
$types = db_fetch_object(db_query($sql)); |
| 799 |
} |
$allowed_types = unserialize($types->types_allowed); |
| 800 |
// Third: Allow access to site wide content .. |
if ($allowed_types[$type] && call_user_func_array($original_callback, $args)) { |
| 801 |
//TODO: Shouldn't this be in a an else block |
return TRUE; |
| 802 |
$sql = "SELECT octa.types_active FROM {og_content_type_admin} octa WHERE octa.gid = -1"; |
} |
| 803 |
$types = db_fetch_object(db_query($sql)); |
} |
| 804 |
$activated_types = unserialize($types->types_active); |
return FALSE; |
|
foreach ($activated_types as $type => $value) { |
|
|
$node_type = isset($type) ? str_replace('_', '-', $type) : NULL; |
|
|
$type_path = "node/add/$node_type"; |
|
|
if ($activated_types[$type] && node_access('create', $type)) { |
|
|
$callbacks[$type_path]['access callback'] = TRUE; |
|
|
} |
|
|
} |
|
| 805 |
} |
} |
| 806 |
|
|
| 807 |
/** |
/** |