| 12 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 13 |
*/ |
*/ |
| 14 |
function restricted_content_menu() { |
function restricted_content_menu() { |
|
/*$items['node/%node/access'] = array( |
|
|
'title' => 'Access', |
|
|
'page callback' => 'drupal_get_form', |
|
|
'page arguments' => array('restricted_content_node_form'), |
|
|
'access callback' => 'restricted_content_tab_access', |
|
|
'access arguments' => array(1), |
|
|
//'weight' => 1, |
|
|
//'file' => 'node.pages.inc', |
|
|
'type' => MENU_LOCAL_TASK, |
|
|
);*/ |
|
| 15 |
$items['admin/content/restricted'] = array( |
$items['admin/content/restricted'] = array( |
| 16 |
'title' => 'Restricted content', |
'title' => 'Restricted content', |
| 17 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 23 |
return $items; |
return $items; |
| 24 |
} |
} |
| 25 |
|
|
|
/*function restricted_content_tab_access($node) { |
|
|
global $user; |
|
|
|
|
|
return user_access('grant content access') || (user_access('grant own content access') && $node->uid === $user->uid); |
|
|
}*/ |
|
|
|
|
| 26 |
/** |
/** |
| 27 |
* Implementation of hook_form_alter(). |
* Implementation of hook_form_alter(). |
| 28 |
*/ |
*/ |
| 29 |
function restricted_content_form_alter(&$form, $form_state, $form_id) { |
function restricted_content_form_alter(&$form, $form_state, $form_id) { |
| 30 |
if ('node_type_form' == $form_id) { |
if ($form_id == 'node_type_form') { |
| 31 |
//node_privacy_byrole_node_type_form($form); |
//restricted_content_node_form($form); |
| 32 |
} |
} |
| 33 |
elseif ($form['#id'] == 'node-form') { |
elseif ($form['#id'] == 'node-form') { |
| 34 |
$form['restricted_content'] = array( |
$default = unserialize(db_result(db_query("SELECT rids FROM {restricted_content} WHERE nid = %d", $form['#node']->nid))); |
| 35 |
'#type' => 'fieldset', |
restricted_content_node_form($form, $default); |
|
'#title' => t('Restricted Access'), |
|
|
'#collapsible' => TRUE, |
|
|
'#collapsed' => TRUE, |
|
|
'#tree' => TRUE, |
|
|
'#access' => restricted_content_form_access($form['#node']), |
|
|
); |
|
|
$form['restricted_content']['rids'] = array( |
|
|
'#type' => 'checkboxes', |
|
|
'#title' => t('Restrict access to users with the following user roles'), |
|
|
'#description' => t('If no roles are selected, the node will be viewable by all users.'), |
|
|
'#options' => user_roles(), |
|
|
'#default_value' => unserialize(db_result(db_query("SELECT rids FROM {restricted_content} WHERE nid = %d", $form['#node']->nid))), |
|
|
); |
|
| 36 |
$form['#submit'][] = 'restricted_content_node_form_submit'; |
$form['#submit'][] = 'restricted_content_node_form_submit'; |
|
//restricted_content_form_node_form_alter($form); |
|
| 37 |
} |
} |
| 38 |
} |
} |
| 39 |
|
|
| 40 |
/** |
/** |
| 41 |
* Implementation of hook_form_FORM_ID_alter(). |
* Option elements to add to node forms. |
| 42 |
*/ |
*/ |
| 43 |
/*function restricted_content_form_node_form_alter(&$form, $form_state = array()) { |
function restricted_content_node_form(&$form, $default) { |
| 44 |
$form['restricted_content'] = array( |
$form['restricted_content'] = array( |
| 45 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 46 |
'#title' => t('Restricted Access'), |
'#title' => t('Restricted Access'), |
| 51 |
); |
); |
| 52 |
$form['restricted_content']['rids'] = array( |
$form['restricted_content']['rids'] = array( |
| 53 |
'#type' => 'checkboxes', |
'#type' => 'checkboxes', |
| 54 |
'#title' => t('Restrict this content from users with any of the following user roles'), |
'#title' => t('Restrict access to users with the following user roles'), |
| 55 |
'#description' => t('If no roles are selected, the node will be viewable by all users.'), |
'#description' => t('If no roles are selected, the node will be viewable by all users.'), |
| 56 |
'#options' => user_roles(), |
'#options' => user_roles(), |
| 57 |
|
'#default_value' => is_array($default) ? $default : array(), |
| 58 |
); |
); |
| 59 |
$form['#submit'][] = 'restricted_content_node_form_submit'; |
$form['#submit'][] = 'restricted_content_node_form_submit'; |
| 60 |
}*/ |
} |
| 61 |
|
|
| 62 |
function restricted_content_node_form_submit($form, $form_state) { |
function restricted_content_node_form_submit($form, $form_state) { |
| 63 |
$nid = $form_state['values']['nid']; |
$nid = $form_state['values']['nid']; |
| 70 |
|
|
| 71 |
function restricted_content_form_access($node) { |
function restricted_content_form_access($node) { |
| 72 |
global $user; |
global $user; |
|
|
|
| 73 |
return user_access('restrict content access') || ($node->nid == $user->uid && user_access('restrict own content access')); |
return user_access('restrict content access') || ($node->nid == $user->uid && user_access('restrict own content access')); |
| 74 |
} |
} |
| 75 |
|
|