/**
  * Overrides OgSelectionHandler::buildEntityFieldQuery().
  */
 public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS')
 {
     $group_type = $this->field['settings']['target_type'];
     // See if the Entity allows for non-member postings
     $user_access = FALSE;
     $event = NULL;
     if ($this->entity && isset($this->entity->og_group_ref[LANGUAGE_NONE][0]['target_id'])) {
         $event = $this->entity->og_group_ref[LANGUAGE_NONE][0]['target_id'];
     } elseif (module_exists('og_context') && isset($_SESSION)) {
         $event = isset($_SESSION['og_context']) ? $_SESSION['og_context'] : og_context('node');
         $event = isset($event['gid']) ? $event['gid'] : NULL;
     }
     if ($event) {
         $user_access = og_user_access('node', $event, "create " . $this->instance['bundle'] . " content") || og_user_access('node', $event, "update own " . $this->instance['bundle'] . " content") || og_user_access('node', $event, "edit any " . $this->instance['bundle'] . " content");
     }
     if (empty($this->instance['field_mode']) || $group_type != 'node' || user_is_anonymous() || !$user_access) {
         return parent::buildEntityFieldQuery($match, $match_operator);
     }
     $handler = EntityReference_SelectionHandler_Generic::getInstance($this->field, $this->instance, $this->entity_type, $this->entity);
     $query = $handler->buildEntityFieldQuery($match, $match_operator);
     // Show only the entities that are active groups.
     $query->fieldCondition(OG_GROUP_FIELD, 'value', 1);
     // Add this property to make sure we will have the {node} table later on in
     // OgCommonsSelectionHandler::entityFieldQueryAlter().
     $query->propertyCondition('nid', 0, '>');
     $query->addMetaData('entityreference_selection_handler', $this);
     // FIXME: http://drupal.org/node/1325628
     unset($query->tags['node_access']);
     $query->addTag('entity_field_access');
     $query->addTag('og');
     return $query;
 }
 /**
  * Attempt to get the Event ID. Input will be an entity with an og_group_ref
  * Or it will be a new entity w/o a node and we will need to use og_context.
  * @param null $entity
  *
  */
 protected function getEventId($entity = NULL)
 {
     if (isset($entity->og_group_ref)) {
         return $entity->og_group_ref[LANGUAGE_NONE][0]['target_id'];
     } else {
         $event_id = og_context();
         if (!empty($event_id)) {
             $event_id['gid'];
         }
     }
     return;
 }
Exemplo n.º 3
0
/**
 * Preprocess a comment_form template.
 */
function opbamboo_preprocess_comment_form(&$vars, $hook)
{
    global $user;
    $node_type = $vars['form']['#node']->type;
    $vars['theme_hook_suggestions'][] = 'comment_form__node_' . $node_type;
    $vars['node_type'] = $node_type;
    $vars['is_anon'] = empty($user->uid);
    $vars['anon_allowed'] = variable_get('ctsi_allow_anonymous_comments_' . $node_type, 0);
    $vars['anon_contact'] = variable_get('comment_anonymous_' . $node_type, COMMENT_ANONYMOUS_MAYNOT_CONTACT);
    if ($group = og_context()) {
        $opg = opg_core_load_opg($group);
        $vars['login_type'] = $opg['login_type'];
        $vars['login'] = $opg['login'];
        $vars['login_text'] = $opg['login']->text;
        $vars['noun'] = $opg['noun'];
        $vars['nouns'] = $opg['nouns'];
    } elseif ($op_forum = op_common_op_forum_load($node_type)) {
        $vars['login_type'] = $op_forum->login_type;
        $vars['login'] = $op_forum->login;
        $vars['login_text'] = $op_forum->login->text;
        $vars['noun'] = empty($op_forum->noun) ? 'proposal' : $op_forum->noun;
        $vars['nouns'] = empty($op_forum->nouns) ? 'proposals' : $op_forum->nouns;
    } else {
        $vars['login_type'] = op_common_get_login_type($node_type);
        $vars['login'] = op_common_op_login_load($vars['login_type']);
        $vars['login_text'] = op_common_op_login_text($vars);
        $vars['noun'] = 'proposal';
        $vars['nouns'] = 'proposals';
    }
    $login_urls = array();
    if ($vars['login']) {
        foreach ($vars['login']->login_types as $login_type => $login_info) {
            $login_urls[$login_type] = $login_info->url;
        }
    } else {
        if ($login_types = op_common_get_ctsi_login_types($login_type)) {
            foreach ($login_types as $k => $v) {
                $login_urls[$k] = $v->url;
            }
        } else {
            // dpm($login_type, 'unable to get ctsi login type info for this OP login type');
        }
    }
    $vars['login_urls'] = $login_urls;
    $vars['me'] = __FUNCTION__;
}
Exemplo n.º 4
0
/**
 * Implements hook_preprocess_page().
 */
function platon_preprocess_page(&$vars)
{
    $path = drupal_get_path('theme', 'platon');
    _platon_inject_css_override();
    drupal_add_library('system', 'jquery.cookie');
    // Prepare the site header attributes.
    $site_header_attributes = array();
    // Change the header image.
    if (theme_get_setting('platon_use_header_background') && theme_get_setting('platon_header_image_path')) {
        if (!isset($site_header_attributes['style'])) {
            $site_header_attributes['style'] = '';
        }
        $site_header_attributes['style'] .= 'background-image: url("' . file_create_url('public://' . theme_get_setting('platon_header_image_path')) . '");';
    } elseif (module_exists('color') && ($scheme = theme_get_setting('scheme'))) {
        // We generate header images, but there not as "clean" as when generated through Photoshop.
        // If one of the provided schemes was chosen, use one of our own header images.
        if (!empty($scheme)) {
            if (!isset($site_header_attributes['style'])) {
                $site_header_attributes['style'] = '';
            }
            $site_header_attributes['style'] .= 'background-image: url("' . base_path() . $path . '/img/' . ($scheme != 'default' ? "{$scheme}-" : '') . 'header-background.jpg")';
        }
    }
    // Set default value.
    $vars['is_og_node'] = FALSE;
    // Add the search form to the page.
    if (module_exists('search') && user_access('search content')) {
        $vars['search_form'] = drupal_get_form('search_form');
    }
    // Flag if we can show the "register" link.
    $register_setting = variable_get('user_register', USER_REGISTER_ADMINISTRATORS_ONLY);
    $vars['can_register'] = $register_setting != USER_REGISTER_ADMINISTRATORS_ONLY;
    // Render the main navigation.
    $vars['main_navigation'] = _platon_get_main_navigation();
    // Create the OG context tabs.
    if (module_exists('og_context')) {
        $group = og_context('node');
        if (!empty($group['gid'])) {
            $tabs = array();
            foreach (array("node/{$group['gid']}" => array('title' => "", 'class' => 'platon-og-context-view-tab platon-og-context-home-tab'), "node/{$group['gid']}/edit" => array('class' => 'platon-og-context-view-tab platon-og-context-settings-tab', 'query' => array('destination' => current_path())), "node/{$group['gid']}/group" => array('class' => 'platon-og-context-view-tab platon-og-context-users-tab'), "node/{$group['gid']}/tools" => array('class' => 'platon-og-context-view-tab platon-og-context-tools-tab'), "node/{$group['gid']}/sort_courses" => array('class' => 'platon-og-context-view-tab platon-og-context-sort-tab')) as $path => $override) {
                $link = menu_get_item($path);
                if (!empty($link) && $link['access']) {
                    if (!empty($override['title'])) {
                        $link['title'] = $override['title'];
                    }
                    if (!empty($override['class'])) {
                        $link['options']['attributes']['class'][] = $link['localized_options']['attributes']['class'][] = $override['class'];
                    }
                    if (!empty($override['query'])) {
                        if (!isset($link['options']['query'])) {
                            $link['options']['query'] = array();
                        }
                        if (!isset($link['localized_options']['query'])) {
                            $link['localized_options']['query'] = array();
                        }
                        $link['localized_options']['query'] += $override['query'];
                        $link['options']['query'] += $override['query'];
                    }
                    $link['options']['attributes']['title'] = $link['localized_options']['attributes']['title'] = $link['title'];
                    //Ajout Axel
                    $link['title'] = '';
                    //Ajout Axel
                    $tabs[] = array('#theme' => 'menu_local_task', '#link' => $link, '#active' => TRUE);
                }
            }
            // Modificaton 10.09.14 - Cédric Carrard
            //
            // Ajout des tools avec des icons dans le menu en haut à droite
            //
            //
            if (isset($vars['node']) && og_is_group('node', $vars['node'])) {
                $groups = $vars['node'];
                foreach (opigno_get_node_tools($groups) as $tool) {
                    $link = menu_get_item($tool['path']);
                    if (!empty($link) && $link['access']) {
                        if (!empty($tool['name'])) {
                            $link['title'] = '';
                            //$tool['name']; Ajout Axel
                        }
                        if (!empty($tool['machine_name'])) {
                            $link['options']['attributes']['class'][] = $link['localized_options']['attributes']['class'][] = 'platon-og-context-view-tab platon-og-context-' . $tool['machine_name'] . '-tab';
                        }
                        if (!empty($tool['query'])) {
                            if (!isset($link['options']['query'])) {
                                $link['options']['query'] = array();
                            }
                            if (!isset($link['localized_options']['query'])) {
                                $link['localized_options']['query'] = array();
                            }
                            $link['localized_options']['query'] += $tool['query'];
                            $link['options']['query'] += $tool['query'];
                        }
                        $link['options']['attributes']['title'] = $link['localized_options']['attributes']['title'] = $tool['name'];
                        //Ajout Axel
                        $tabs[] = array('#theme' => 'menu_local_task', '#link' => $link, '#active' => TRUE);
                    }
                }
            } else {
                $group = og_context('node');
                if (current_path() !== "node/{$group['gid']}") {
                    $node = node_load($group['gid']);
                    foreach (opigno_get_node_tools($node) as $tool) {
                        $link = menu_get_item($tool['path']);
                        if (!empty($link) && opigno_tool_access($tool)) {
                            if (!empty($tool['name'])) {
                                $link['title'] = '';
                                //$tool['name']; Ajout Axel
                            }
                            if (!empty($tool['machine_name'])) {
                                $link['options']['attributes']['class'][] = $link['localized_options']['attributes']['class'][] = 'platon-og-context-view-tab platon-og-context-' . $tool['machine_name'] . '-tab';
                            }
                            if (!empty($tool['query'])) {
                                if (!isset($link['options']['query'])) {
                                    $link['options']['query'] = array();
                                }
                                if (!isset($link['localized_options']['query'])) {
                                    $link['localized_options']['query'] = array();
                                }
                                $link['localized_options']['query'] += $tool['query'];
                                $link['options']['query'] += $tool['query'];
                            }
                            $link['options']['attributes']['title'] = $link['localized_options']['attributes']['title'] = $tool['name'];
                            //Ajout Axel
                            $tabs[] = array('#theme' => 'menu_local_task', '#link' => $link, '#active' => TRUE);
                        }
                    }
                }
            }
            // Modificaton 10.09.14 - Cédric Carrard
            //
            // On enleve le menu primary sur le page des utilisateur
            //
            if (!empty($tabs)) {
                if (isset($vars['node']) && !platon_display_tabs($vars['node'])) {
                    unset($vars['tabs']['#primary']);
                }
                $vars['og_context_navigation'] = render($tabs);
            }
            if (isset($vars['node']) && $vars['node']->nid == $group['gid']) {
                // $vars['hide_tabs'] = TRUE;
                $vars['is_og_node'] = TRUE;
            }
        }
    }
    // Show the number of unread messages.
    if (function_exists('privatemsg_unread_count')) {
        global $user;
        $unread = privatemsg_unread_count($user);
        drupal_add_js(array('platon' => array('unreadMessages' => $unread)), 'setting');
    }
    // Use a custom markup for the front page if anonymous ?
    $settings = theme_get_setting('platon_home_page_settings');
    empty($settings) ? $settings = variable_get('theme_platon_settings') : null;
    if (empty($vars['user']->uid) && $vars['is_front'] && $settings['platon_use_home_page_markup']) {
        drupal_add_js(path_to_theme() . '/js/vendor/slick.js');
        drupal_add_css(path_to_theme() . '/css/vendor/slick.css');
        $html = '<ul class="homepage-slider">';
        $i = 0;
        foreach ($settings as $key => $value) {
            if (is_array($value) && $key != 'platon_home_page_markup') {
                if (!empty($value['platon_home_page_markup']['value'])) {
                    $markupValue = $value['platon_home_page_markup']['value'];
                } else {
                    $markupValue = $value['platon_home_page_markup_wrapper']['platon_home_page_markup']['value'];
                }
                if (!empty($value['platon_home_page_markup']['format'])) {
                    $markupFormat = $value['platon_home_page_markup']['format'];
                } else {
                    $markupFormat = $value['platon_home_page_markup_wrapper']['platon_home_page_markup']['format'];
                }
                if (!empty($value['platon_home_page_markup']['background'])) {
                    $markupBackground = $value['platon_home_page_markup']['background'];
                } else {
                    $markupBackground = $value['platon_home_page_image_path'];
                }
                if (!empty($markupValue)) {
                    $i++;
                    $value = check_markup($markupValue, $markupFormat);
                    if (!empty($value)) {
                        $html .= '<li style="background-image: url(' . base_path() . 'sites/default/files/' . $markupBackground . ');"><div class="content">' . $value . '</div></li>';
                    }
                }
            }
        }
        $html .= '</ul><div class="slider-footer"><div class="slider-counter"><div class="top">1</div><div class="bottom">' . $i . '</div></div></div>';
        drupal_set_title($vars['site_name']);
        $vars['page']['content'] = $html;
        $vars['page']['content'] = $html;
    }
    // Render the site header attributes.
    $vars['site_header_attributes'] = drupal_attributes($site_header_attributes);
    if (variable_get('platon_group_style', 1) == 1) {
        if (isset($vars['group_state'])) {
            $vars['group_state'] = platon_render_group_state($vars['group_state']);
        }
    }
}
Exemplo n.º 5
0
/**
 * Custom function that returns the group node of the current group context.
 */
function unl_fourone_og_get_current_group()
{
    if (module_exists('og_context')) {
        $group_context = og_context();
        $view = views_get_page_view();
        // Set the og context if we are viewing a Views Page display with one of the
        //  contextual filters (in the switch) combined with an "OG membership" relationship.
        if (empty($group_context) && ($view = views_get_page_view())) {
            if ($view->display_handler->plugin_name == 'page') {
                foreach ($view->argument as $key => $value) {
                    switch ($key) {
                        case 'gid':
                            og_context('node', node_load($view->argument['gid']->argument));
                            $group_context = og_context();
                            break;
                        case 'title':
                            $query = new EntityFieldQuery();
                            $entities = $query->entityCondition('entity_type', 'node')->propertyCondition('title', $view->argument['title']->argument)->propertyCondition('status', 1)->range(0, 1)->execute();
                            if (!empty($entities['node'])) {
                                $keys = array_keys($entities['node']);
                                og_context('node', node_load(array_shift($keys)));
                                $group_context = og_context();
                            }
                            break;
                            // This is a hack using a field with the specific name 'field_url_path' because
                            //  relying on path alias does not work: https://drupal.org/node/1658352#comment-7927861
                        // This is a hack using a field with the specific name 'field_url_path' because
                        //  relying on path alias does not work: https://drupal.org/node/1658352#comment-7927861
                        case 'field_url_path_value':
                            $query = new EntityFieldQuery();
                            $entities = $query->entityCondition('entity_type', 'node')->fieldCondition('field_url_path', 'value', $view->argument['field_url_path_value']->argument)->propertyCondition('status', 1)->range(0, 1)->execute();
                            if (!empty($entities['node'])) {
                                $keys = array_keys($entities['node']);
                                og_context('node', node_load(array_shift($keys)));
                                $group_context = og_context();
                            }
                            break;
                    }
                }
            }
        }
        if ($group_context) {
            return node_load($group_context['gid']);
        }
    }
    return false;
}