Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @file
- * This custom code is intended to handle situations in which a directory person is privately flagged,
- * and the user does not have permission to see that person.
- */
- include_once('directory.features.inc');
- /**
- * Implements hook_permission.
- *
- * Provides a permission to restrict the visibility of private-flagged directory persons.
- */
- function directory_permission() {
- return array('view private directory persons' => array('title' => t('View private directory persons')));
- }
- /**
- * Implements hook_node_access.
- *
- * Restricts visibility of private-flagged directory persons to people with the appropriate permission.
- *
- * @param node
- * The node being accessed.
- * @param op
- * The operation being requested.
- */
- function directory_node_access($node, $op) {
- if ($node->type == 'directory_person') {
- $private = flag_get_flag('directory_person_private') or die ('private flag does not exist');
- if ($op == 'view' && !user_access('view private directory persons') && $private->is_flagged($node->nid)) {
- return NODE_ACCESS_DENY;
- }
- } else {
- return NODE_ACCESS_IGNORE;
- }
- }
- /**
- * Implements hook_page_alter.
- *
- * Removes redundant public directory index block if user has access to private directory index block.
- *
- * @param page
- * The page array that is used to build the page.
- */
- function directory_page_alter(&$page) {
- if (user_access('view private directory persons')) {
- foreach (system_region_list(variable_get('theme_default'), REGIONS_VISIBLE) as $region => $value) {
- if (isset($page[$region]['views_directory-directory_block_index'])) {
- unset($page[$region]['views_directory-directory_block_index']);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment