| 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 2008/10/01 22:33:38 paulbooker Exp $; |
* @version $Id: og_content_type_admin.module,v 1.15.2.2 2008/10/09 13:43:47 paulbooker Exp $; |
| 20 |
* @package OG_CTA |
* @package OG_CTA |
| 21 |
* @category NeighborForge |
* @category NeighborForge |
| 22 |
* @author Ryan Constantine |
* @author Ryan Constantine |
| 143 |
|
|
| 144 |
function _og_content_type_admin_is_admin_access_callback($nid){ |
function _og_content_type_admin_is_admin_access_callback($nid){ |
| 145 |
$group = node_load($nid); |
$group = node_load($nid); |
| 146 |
//$return = (isset($group->og_selective) && _og_content_type_admin_is_admin($group)) ? TRUE : FALSE; |
$return = (isset($group->og_selective) && _og_content_type_admin_is_admin($group)) ? TRUE : FALSE; |
|
return TRUE; |
|
| 147 |
return $return; |
return $return; |
| 148 |
} |
} |
| 149 |
|
|
| 171 |
global $user; |
global $user; |
| 172 |
$links = array(); |
$links = array(); |
| 173 |
if ($group) { |
if ($group) { |
| 174 |
if ((_og_content_type_admin_is_admin($group) && !variable_get('og_content_type_admin_no_change', 0)) || $user->uid == 1) { |
if (_og_content_type_admin_is_admin($group)) { |
| 175 |
$links[] = l(t('Manage group content types'), "node/$group->nid/ogct", array('title' => t('Lets you decide which content types your group\'s users can create.'))); |
$links[] = l(t('Manage group content types'), "node/$group->nid/ogct", array('title' => t('Lets you decide which content types your group\'s users can create.'))); |
| 176 |
} |
} |
| 177 |
} |
} |
| 757 |
* page's listing, nor does it remove the menu items within the OG 'group detail' menu. It also doesn't account |
* page's listing, nor does it remove the menu items within the OG 'group detail' menu. It also doesn't account |
| 758 |
* for directly entering in an illegal url. Other functions handle these problems. |
* for directly entering in an illegal url. Other functions handle these problems. |
| 759 |
*/ |
*/ |
| 760 |
function og_content_type_admin_menu_alter(&$callbacks) { |
function og_content_type_admin_menu_alter(&$callbacks) { // $types used twice!!!!! |
| 761 |
global $user; |
global $user; |
| 762 |
|
|
| 763 |
if ($node = og_get_group_context()) { |
if ($node = og_get_group_context()) { |
| 764 |
$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"; |
| 765 |
//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 |
| 766 |
$types = db_fetch_object(db_query($sql, $node->nid)); |
$types = db_fetch_object(db_query($sql, $node->nid)); |
| 772 |
$types = db_fetch_object(db_query($sql)); |
$types = db_fetch_object(db_query($sql)); |
| 773 |
|
|
| 774 |
} |
} |
| 775 |
$activated_types = unserialize($types->types_active); |
$activated_types = unserialize($types->types_active); |
| 776 |
|
|
| 777 |
foreach ($activated_types as $type => $value) { |
foreach ($activated_types as $type => $value) { |
| 778 |
$url = str_replace('_', '-', $type); |
$node_type = isset($type) ? str_replace('_', '-', $type) : NULL; //print " ".$type; |
| 779 |
$type_path = "node/add/$url"; |
$type_path = "node/add/$node_type"; |
| 780 |
$callbacks[$type_path]['access callback'] = FALSE; |
$callbacks[$type_path]['access callback'] = FALSE; |
| 781 |
if ($value != DEACTIVATED) { |
$allowed_for_group_admins = (($allowed_types[$type] != NOT_ASSIGNED_TO_GROUP) && (_og_content_type_admin_is_admin_content_access_nid($gid))); |
| 782 |
|
$allowed_for_users = (($activated_types[$type] != DEACTIVATED) && (!_og_content_type_admin_is_admin_content_access_nid($gid))); |
| 783 |
|
$types = node_get_types(); |
| 784 |
|
if ((($user->uid == 1) && isset($types[$type])) || (($look_at_allowed == 0) && isset($types[$type]) && node_access('create', $type) && ($activated_types[$type] != DEACTIVATED)) || (($look_at_allowed == 1) && isset($types[$type]) && node_access('create', $type) && ($allowed_for_group_admins || $allowed_for_users)) ) { |
| 785 |
$callbacks[$type_path]['access callback'] = TRUE; |
$callbacks[$type_path]['access callback'] = TRUE; |
| 786 |
} |
} |
| 787 |
} |
} |
| 788 |
} |
$callbacks['node/add']['page callback'] = 'og_content_type_admin_node_add'; |
| 789 |
|
} |
| 790 |
|
|
| 791 |
|
|
| 792 |
|
/** |
| 793 |
|
* Interception of the node module's node_add function. |
| 794 |
|
* |
| 795 |
|
* Present a node submission form or a set of links to such forms. |
| 796 |
|
*/ |
| 797 |
|
function og_content_type_admin_node_add($type = NULL) { |
| 798 |
|
global $user, $_GET; |
| 799 |
|
|
| 800 |
|
$gid = NULL; |
| 801 |
|
|
| 802 |
|
//if there is a group context, get the active types for the group, otherwise, use the site-wide list |
| 803 |
|
if (is_array($_GET[gids])) { |
| 804 |
|
$gid = $_GET[gids][0]; |
| 805 |
|
$sql = "SELECT octa.types_active, octa.types_allowed FROM {og_content_type_admin} octa WHERE octa.gid = %d"; |
| 806 |
|
//if we're keeping track of this group, get it's active types, otherwise, get the defaults |
| 807 |
|
if (!$result = db_fetch_object(db_query($sql, $_GET[gids][0]))) { |
| 808 |
|
$result = db_fetch_object(db_query($sql, 0)); |
| 809 |
|
} |
| 810 |
|
$activated_types = unserialize($result->types_active); |
| 811 |
|
$allowed_types = unserialize($result->types_allowed); |
| 812 |
|
$look_at_allowed = 1; |
| 813 |
|
} |
| 814 |
|
else { |
| 815 |
|
$sql = "SELECT octa.types_active FROM {og_content_type_admin} octa WHERE octa.gid = -1"; |
| 816 |
|
$holder = db_fetch_object(db_query($sql)); |
| 817 |
|
$activated_types = unserialize($holder->types_active); |
| 818 |
|
$look_at_allowed = 0; |
| 819 |
|
} |
| 820 |
|
|
| 821 |
|
$types = node_get_types(); |
| 822 |
|
if (module_exists('nf_registration_mod')) { |
| 823 |
|
$pageroute_types = _nf_registration_mod_menu_status(); |
| 824 |
|
foreach ($pageroute_types as $typea => $nums) { |
| 825 |
|
if ($nums[1] == 48) { |
| 826 |
|
if (isset($types[$typea])) { |
| 827 |
|
unset($types[$typea]); |
| 828 |
|
} |
| 829 |
|
} |
| 830 |
|
} |
| 831 |
|
} |
| 832 |
|
$type = isset($type) ? str_replace('-', '_', $type) : NULL; |
| 833 |
|
$allowed_for_group_admins = (($allowed_types[$type] != NOT_ASSIGNED_TO_GROUP) && (_og_content_type_admin_is_admin_content_access_nid($gid))); |
| 834 |
|
$allowed_for_users = (($activated_types[$type] != DEACTIVATED) && (!_og_content_type_admin_is_admin_content_access_nid($gid))); |
| 835 |
|
|
| 836 |
|
// If a node type has been specified, validate its existence and output the form if authorized. |
| 837 |
|
// If the user is site admin, allow all content types. |
| 838 |
|
if (($user->uid == 1) && isset($types[$type])) { |
| 839 |
|
// Initialize settings: |
| 840 |
|
$node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type); |
| 841 |
|
drupal_set_title(t('Submit @name', array('@name' => $types[$type]->name))); |
| 842 |
|
$output = drupal_get_form($type. '_node_form', $node); |
| 843 |
|
}// If we don't know the gid, then use site-wide types. Only allow types that aren't DEACTIVATED. |
| 844 |
|
elseif (($look_at_allowed == 0) && isset($types[$type]) && node_access('create', $type) && ($activated_types[$type] != DEACTIVATED)) { |
| 845 |
|
// Initialize settings: |
| 846 |
|
$node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type); |
| 847 |
|
drupal_set_title(t('Submit @name', array('@name' => $types[$type]->name))); |
| 848 |
|
$output = drupal_get_form($type. '_node_form', $node); |
| 849 |
|
}// If we have the gid, check if the user is a group admin. If so, allow them to create ALLOWED types that are not activated for their group members. |
| 850 |
|
// Otherwise, if the user is not a group admin, they can only create types that are not DEACTIVATED. |
| 851 |
|
elseif (($look_at_allowed == 1) && isset($types[$type]) && node_access('create', $type) && ($allowed_for_group_admins || $allowed_for_users)) { |
| 852 |
|
// Initialize settings: |
| 853 |
|
$node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type); |
| 854 |
|
drupal_set_title(t('Submit @name', array('@name' => $types[$type]->name))); |
| 855 |
|
$output = drupal_get_form($type. '_node_form', $node); |
| 856 |
|
} |
| 857 |
|
else { |
| 858 |
|
// If no (valid) node type has been provided, display a node type overview. |
| 859 |
|
// Make sure to use the site-wide settings since we're on the node/add page in this case. |
| 860 |
|
drupal_set_title(t('Create content')); |
| 861 |
|
foreach ($types as $type) { |
| 862 |
|
if (function_exists($type->module. '_form') && node_access('create', $type->type) && (($activated_types[$type->type] != DEACTIVATED) || ($user->uid == 1))) { |
| 863 |
|
$type_url_str = str_replace('_', '-', $type->type); |
| 864 |
|
$title = t('Add a new @s.', array('@s' => $type->name)); |
| 865 |
|
if ($gid != NULL) { |
| 866 |
|
$out = '<dt>' .l(drupal_ucfirst($type->name), "node/add/$type_url_str", array('title' => $title), "gids[]=$gid"). '</dt>'; |
| 867 |
|
} |
| 868 |
|
else { |
| 869 |
|
$out = '<dt>' .l(drupal_ucfirst($type->name), "node/add/$type_url_str", array('title' => $title)). '</dt>'; |
| 870 |
|
} |
| 871 |
|
$out .= '<dd>' .filter_xss_admin($type->description). '</dd>'; |
| 872 |
|
$item[$type->type] = $out; |
| 873 |
|
} |
| 874 |
|
} |
| 875 |
|
|
| 876 |
|
if (isset($item)) { |
| 877 |
|
uksort($item, 'strnatcasecmp'); |
| 878 |
|
$output = t('Choose the appropriate item from the list:'). '<dl>' .implode('', $item). '</dl>'; |
| 879 |
|
} |
| 880 |
|
else { |
| 881 |
|
drupal_set_title(t('Invalid Content Type')); |
| 882 |
|
$output = t('Either the content type you are trying to create does not exist, |
| 883 |
|
or you are not authorized to access the content type you have tried to create in the current context. |
| 884 |
|
\'Create\' a content type by selecting from either the group menu or the \'Create content\' menu instead.'); |
| 885 |
|
} |
| 886 |
|
} |
| 887 |
|
|
| 888 |
|
return $output; |
| 889 |
|
} // function og_content_type_admin_node_add() |
| 890 |
|
|
| 891 |
/** |
/** |
| 892 |
* Implementation of hook_block(). See og_content_type_admin_block_details. |
* Implementation of hook_block(). See og_content_type_admin_block_details. |