View source
<?php
include_once 'oa_core.features.inc';
include_once 'includes/oa_core.cache.inc';
include_once 'includes/oa_core.util.inc';
include_once 'includes/oa_core.access.inc';
include_once 'includes/oa_core.context.inc';
include_once 'includes/oa_core.login.inc';
include_once 'includes/oa_core.theme.inc';
include_once 'includes/oa_core.fields.inc';
define('OA_SPACE_TYPE', 'oa_space');
define('OA_SECTION_TYPE', 'oa_section');
define('OA_GROUP_TYPE', 'oa_group');
define('OA_TEAM_TYPE', 'oa_team');
define('OA_SECTION_FIELD', 'oa_section_ref');
define('OA_SPACE_FIELD', 'og_group_ref');
define('OA_ACCESS_REALM', 'oa_access');
define('OA_UNPUBLISHED_REALM', 'oa_unpublished');
define('OA_SPACE_CURRENT', 'CURRENT');
define('OA_OLD_FILE_EXTENSIONS_DEFAULT', 'jpg jpeg gif png txt doc docx xls xlsx pdf ppt pptx pps ppsx odt ods odp mp3 mov mp4 m4a m4v mpeg avi ogg oga ogv weba webp webm');
define('OA_FILE_EXTENSIONS_DEFAULT', 'jpg jpeg gif png txt doc docx xls xlsx pdf ppt pptx pps ppsx odt ods odp mp3 mov mp4 m4a m4v mpeg avi ogg oga ogv weba webp webm zip tgz gz key dotx');
function oa_core_ctools_plugin_directory($owner, $plugin_type) {
if ($owner == 'ctools') {
return 'plugins/' . $plugin_type;
}
elseif ($owner == 'entityreference') {
return "plugins/entityreference/{$plugin_type}";
}
return '';
}
function oa_core_init() {
menu_tree_set_path('og-menu-single', '');
if (arg(0) == 'media' && arg(1) == 'browser') {
drupal_add_css(drupal_get_path('module', 'oa_core') . '/css/oa_core.media.css', array(
'group' => CSS_THEME,
'weight' => -1,
));
}
}
function oa_core_menu() {
$items['admin/openatrium'] = array(
'title' => 'Open Atrium',
'description' => 'Administer Open Atrium.',
'weight' => 0,
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array(
'administer site configuration',
),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
$items['admin/openatrium/section-templates'] = array(
'title' => 'Section Templates',
'description' => 'Configure panelizer section templates',
'weight' => 0,
'access arguments' => array(
'administer site configuration',
),
'page callback' => 'oa_core_section_template',
);
$items['admin/openatrium/space-templates'] = array(
'title' => 'Space Templates',
'description' => 'Configure panelizer space templates',
'weight' => 0,
'access arguments' => array(
'administer site configuration',
),
'page callback' => 'oa_core_space_template',
);
$items['admin/openatrium/setting'] = array(
'title' => 'Config',
'description' => 'Configuration settings related to Open Atrium',
'weight' => -1,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'oa_core_configure_form',
),
'access arguments' => array(
'administer site configuration',
),
);
$items['admin/openatrium/groups'] = array(
'title' => 'Groups',
'description' => 'Configure Open Atrium Groups',
'weight' => 0,
'access arguments' => array(
'administer site configuration',
),
'page callback' => 'oa_core_show_groups',
);
$items['group/%/%/remove/%/%'] = array(
'title' => 'Remove member',
'type' => MENU_CALLBACK,
'page callback' => 'oa_core_remove_member',
'page arguments' => array(
1,
2,
4,
5,
),
'access callback' => 'og_ui_user_access_group',
'access arguments' => array(
'manage members',
1,
2,
),
);
$items['group/%/%/block/%'] = array(
'title' => 'Block member',
'type' => MENU_CALLBACK,
'page callback' => 'oa_core_block_member',
'page arguments' => array(
1,
2,
4,
),
'access callback' => 'og_ui_user_access_group',
'access arguments' => array(
'manage members',
1,
2,
),
);
$items['group/%/%/add-member/%'] = array(
'title' => 'Add member',
'type' => MENU_CALLBACK,
'page callback' => 'oa_core_add_member',
'page arguments' => array(
1,
2,
4,
),
'access callback' => 'user_is_logged_in',
);
$items['group/%/%/add-admin/%'] = array(
'title' => 'Add Admin',
'type' => MENU_CALLBACK,
'page callback' => 'oa_core_add_admin',
'page arguments' => array(
1,
2,
4,
),
'access callback' => 'og_ui_user_access_group',
'access arguments' => array(
'manage members',
1,
2,
),
);
$items['group/%/%/remove-admin/%'] = array(
'title' => 'Add Admin',
'type' => MENU_CALLBACK,
'page callback' => 'oa_core_remove_admin',
'page arguments' => array(
1,
2,
4,
),
'access callback' => 'og_ui_user_access_group',
'access arguments' => array(
'manage members',
1,
2,
),
);
$items['node/add/oa-space/%'] = array(
'title' => 'Create Space',
'page callback' => 'oa_core_create_space_page_callback',
'page arguments' => array(
OA_SPACE_TYPE,
3,
),
'access callback' => 'oa_core_create_space_access',
'access arguments' => array(
3,
),
'type' => MENU_CALLBACK,
);
if (module_exists('devel')) {
$items['oa-core/system-elements'] = array(
'access arguments' => array(
'access devel information',
),
'page callback' => 'oa_core_element_test_page',
'type' => MENU_CALLBACK,
'file' => 'oa_core.fields.inc',
'file path' => drupal_get_path('module', 'oa_core') . '/includes',
);
}
$items['oacoreselect2widget/ajax/%/%/%/%'] = array(
'title' => 'Ajax callback',
'page callback' => 'oa_core_select2widget_ajax_callback',
'page arguments' => array(
FALSE,
2,
3,
4,
5,
),
'access callback' => 'select2widget_autocomplete_access',
'access arguments' => array(
2,
3,
4,
5,
),
'type' => MENU_CALLBACK,
);
$items['oacoreselect2widgetpanes/ajax/%/%/%/%'] = array(
'title' => 'Ajax callback',
'page callback' => 'oa_core_select2widget_ajax_callback',
'page arguments' => array(
TRUE,
2,
3,
4,
5,
),
'access callback' => 'select2widget_autocomplete_access',
'access arguments' => array(
2,
3,
4,
5,
),
'type' => MENU_CALLBACK,
);
return $items;
}
function oa_core_select2widget_ajax_callback($add_current_option, $field_name, $entity_type, $bundle_name, $entity_id = '') {
$string = '';
if (isset($_GET['search_string']) && !empty($_GET['search_string'])) {
$string = $_GET['search_string'];
}
$field = field_info_field('og_group_ref');
$instance = field_info_instance($entity_type, $field_name, $bundle_name);
$matches = array();
$options = array();
$entity = NULL;
if ($entity_id !== 'NULL') {
$entity = entity_load_single($entity_type, $entity_id);
if (!$entity || !entity_access('view', $entity_type, $entity)) {
return MENU_ACCESS_DENIED;
}
}
$instance['field_mode'] = 'all';
$settings = $instance['settings']['behaviors']['og_widget']['default']['widget_settings']['select2widgetajax'];
$handler = entityreference_get_selection_handler($field, $instance, $entity_type, $entity);
$entity_labels = $handler
->getReferencableEntities($string, $settings['match_operator'], 20);
$matches = array();
if ($add_current_option) {
$matches[] = array(
'id' => OA_SPACE_CURRENT,
'title' => _oa_core_select2widget_current_label(),
'data' => '<div class="reference-select2widget">' . _oa_core_select2widget_current_label() . '</div>',
);
}
$matches[] = array(
'id' => 'All',
'title' => _oa_core_select2widget_all_label(),
'data' => '<div class="reference-select2widget">' . _oa_core_select2widget_all_label() . '</div>',
);
$matches = array_merge($matches, select2widget_render_modes($entity_labels, $settings['view_mode'], $field['settings']['target_type']));
drupal_json_output($matches);
}
function _oa_core_select2widget_all_label() {
return t('- Any -');
}
function _oa_core_select2widget_current_label() {
return t('- Active Space -');
}
function oa_core_create_space_page_callback($type, $space_tid) {
global $user;
if ($space_type = taxonomy_term_load($space_tid)) {
$node = (object) array(
'uid' => $user->uid,
'name' => isset($user->name) ? $user->name : '',
'type' => $type,
'language' => LANGUAGE_NONE,
'is_new' => TRUE,
);
$title = t('Create @name', array(
'@name' => $space_type->name,
));
$pattern = '';
if ($type == OA_SPACE_TYPE) {
$pattern = '/space/i';
}
elseif ($type == OA_SECTION_TYPE) {
$pattern = '/section/i';
}
if (!empty($pattern) && preg_match($pattern, $title) == 0) {
$types = node_type_get_types();
$title = t('Create @name @type', array(
'@name' => $space_type->name,
'@type' => $types[$type]->name,
));
}
drupal_set_title($title);
module_load_include('inc', 'ctools', 'page_manager/plugins/tasks/node_edit');
return page_manager_node_edit($node);
}
return MENU_NOT_FOUND;
}
function oa_core_create_space_access($tid) {
$gid = oa_core_get_space_context(TRUE);
$tids = oa_core_get_allowed_space_terms($gid);
return !isset($tids) || empty($tids) || isset($tids[$tid]);
}
function oa_core_menu_alter(&$items) {
if (!empty($items['node/%/group'])) {
$items['node/%/group']['title'] = 'Config';
}
}
function oa_core_preprocess_html(&$vars) {
$classes = oa_core_body_classes();
if (!empty($GLOBALS['oa_hide_page_title'])) {
$classes[] = 'oa-no-page-title';
}
if (!empty($classes)) {
$vars['classes_array'] = empty($vars['classes_array']) ? $classes : array_merge($vars['classes_array'], $classes);
}
}
function oa_core_configure_form($form, &$form_state) {
$form = array();
drupal_add_js("misc/collapse.js");
drupal_add_js("misc/vertical-tabs.js");
$form['oa_settings'] = array(
'#type' => 'vertical_tabs',
'#weight' => 99,
'#prefix' => '<div class="oa-vertical-tabs">',
'#suffix' => '</div>',
);
$hook = 'oa_settings_form';
foreach (module_implements($hook) as $module) {
$function = $module . '_' . $hook;
if (function_exists($function)) {
$child_forms = call_user_func_array($function, array(
&$form_state,
));
foreach ($child_forms as $key => $child_form) {
if (!isset($form[$child_form['caption']])) {
$form[$child_form['caption']] = array(
'#type' => 'fieldset',
'#title' => $child_form['caption'],
'#group' => 'oa_settings',
'#attributes' => array(
'class' => array(
'collapsible',
),
),
);
}
$form[$child_form['caption']][] = $child_form['form'];
if (!empty($child_form['submit'])) {
$form['#submit'][] = $child_form['submit'];
}
}
}
}
return system_settings_form($form);
}
function oa_core_app_configure_form($form, &$form_state) {
$form = array();
if (($app_name = arg(3)) && ($function = $app_name . '_oa_settings_form') && function_exists($function)) {
$child_forms = call_user_func_array($function, array(
&$form_state,
));
if (count($child_forms) > 1) {
drupal_add_js("misc/collapse.js");
drupal_add_js("misc/vertical-tabs.js");
$form['oa_settings'] = array(
'#type' => 'vertical_tabs',
'#weight' => 99,
'#prefix' => '<div class="oa-vertical-tabs">',
'#suffix' => '</div>',
);
foreach ($child_forms as $key => $child_form) {
$form[$child_form['caption']] = array(
'#type' => 'fieldset',
'#title' => $child_form['caption'],
'#group' => 'oa_settings',
'#attributes' => array(
'class' => array(
'collapsible',
),
),
);
$form[$child_form['caption']][] = $child_form['form'];
if (!empty($child_form['submit'])) {
$form['#submit'][] = $child_form['submit'];
}
}
}
elseif (count($child_forms)) {
$child_form = reset($child_forms);
$form['title']['#markup'] = '<h2>' . $child_form['caption'] . '</h2>';
$form += $child_form['form'];
if (!empty($child_form['submit'])) {
$form['#submit'][] = $child_form['submit'];
}
}
}
return $form ? system_settings_form($form) : array(
'#markup' => t('Unable to generate form'),
);
}
function oa_core_og_fields_info() {
$items[OA_SECTION_FIELD] = array(
'no ui' => TRUE,
'type' => array(
'group content',
),
'description' => t('Determine to which Open Atrium section this space content is assigned to.'),
'field' => array(
'field_name' => OA_SECTION_FIELD,
'type' => 'entityreference',
'cardinality' => 1,
'module' => 'entityreference',
'settings' => array(
'handler' => 'base',
'handler_settings' => array(
'behaviors' => array(
'views-select-list' => array(
'status' => 0,
),
),
'sort' => array(
'type' => 'none',
),
'target_bundles' => array(
OA_SECTION_TYPE => OA_SECTION_TYPE,
),
),
'target_type' => 'node',
),
'translatable' => '0',
),
'instance' => array(
'label' => t('Open Atrium Section'),
'options_limit' => 1,
'options_limit_empty_behaviour' => 1,
'options_limit_fields' => array(
'body' => 0,
'oa_section_ref' => 0,
'og_group_ref' => 'og_group_ref',
),
'options_optomize_entityreferences' => 1,
'widget' => array(
'active' => 0,
'module' => 'options',
'settings' => array(
'match_operator' => 'CONTAINS',
'path' => '',
'size' => 60,
),
'type' => 'options_select',
'weight' => '7',
),
),
);
return $items;
}
function oa_core_og_fields_info_alter(&$return) {
if (isset($return['og_group_ref'])) {
$return['og_group_ref']['instance']['settings'] = array(
'behaviors' => array(
'og_widget' => array(
'access_override' => 1,
'admin' => array(
'widget_settings' => array(
'select2widgetajax' => array(
'match_operator' => 'CONTAINS',
'min_char' => 1,
'view_mode' => 'teaser',
'width' => '100%',
),
),
'widget_type' => 'select2widgetajax',
),
'default' => array(
'widget_settings' => array(
'select2widgetajax' => array(
'match_operator' => 'CONTAINS',
'min_char' => 1,
'view_mode' => 'teaser',
'width' => '100%',
),
),
'widget_type' => 'select2widgetajax',
),
'status' => TRUE,
),
),
'user_register_form' => FALSE,
);
}
}
function oa_core_form_node_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['panelizer'])) {
$form['panelizer']['page_manager']['name']['#title'] = t('Select Layout');
}
$fields = array(
OA_SPACE_FIELD,
);
if (empty($form['#node']->clone_from_original_nid)) {
$fields[] = OA_PARENT_SPACE;
}
foreach ($fields as $field_name) {
if (!empty($form['#node']->{$field_name}[LANGUAGE_NONE][0]['target_id']) && isset($form[$field_name][LANGUAGE_NONE][0]['default']) && empty($form[$field_name][LANGUAGE_NONE][0]['default']['#default_value']) && ($group = node_load($form['#node']->{$field_name}[LANGUAGE_NONE][0]['target_id'])) && (!isset($form[$field_name][LANGUAGE_NONE][0]['admin']['#default_value']) || strpos($form[$field_name][LANGUAGE_NONE][0]['admin']['#default_value'], $group->title . ' (' . $group->nid . ')') !== FALSE && in_array($group->nid, oa_core_get_groups_by_user(NULL, 'node')))) {
$form[$field_name][LANGUAGE_NONE][0]['default']['#default_value'] = $group->title . ' (' . $group->nid . ')';
$form[$field_name][LANGUAGE_NONE][0]['default']['#init'][$group->nid] = $form[$field_name][LANGUAGE_NONE][0]['default']['#default_value'];
if (isset($form[$field_name][LANGUAGE_NONE][0]['admin'])) {
$form[$field_name][LANGUAGE_NONE][0]['admin']['#default_value'] = '';
$form[$field_name][LANGUAGE_NONE][0]['admin']['#init'] = array();
}
}
}
if (isset($form['field_oa_space_type']) && !isset($form['#node']->nid)) {
$options = oa_core_get_allowed_space_terms();
if (isset($options)) {
$form['field_oa_space_type'][LANGUAGE_NONE]['#options'] = $options;
}
}
}
function oa_core_form_node_delete_confirm_alter(&$form, $form_state) {
$form['#submit'][] = 'oa_core_node_delete_redirect';
if (variable_get('og_use_queue', FALSE) && ($orphans = oa_core_get_orphans('node', $form['#node']->nid))) {
$form['oa_core_orphans'] = array(
'#title' => t('Orphan Content'),
'#description' => t('How to handle orphan content (content that is a member of this group but no others)'),
'#type' => 'radios',
'#options' => array(
'nothing' => t('Orphan (remove membership but otherwise leave content alone)'),
'delete' => t('Delete'),
'move' => t('Move'),
),
'#default_value' => 'nothing',
);
$form['oa_core_orphans_og_group_ref'] = array(
'#type' => 'og_group_ref',
'#title' => t('Space'),
'#default_value' => array(),
'#states' => array(
'visible' => array(
':input[name="oa_core_orphans"]' => array(
'value' => 'move',
),
),
),
);
$form['#validate'][] = 'oa_core_form_node_delete_confirm_validate';
}
}
function oa_core_form_node_delete_confirm_validate($form, &$form_state) {
$node = $form['#node'];
if ($form_state['values']['oa_core_orphans'] == 'move') {
$gid = $form_state['values']['oa_core_orphans_og_group_ref'];
if (empty($gid) || !is_numeric($gid) || !($group = node_load($gid))) {
form_set_error('oa_core_orphans', t('Please select a space to move the content to.'));
}
elseif ($gid === $node->nid) {
form_set_error('oa_core_orphans', t('Please select a space that is not the current space to move the content to.'));
}
elseif (!node_access('update', $group)) {
form_set_error('oa_core_orphans', t('Please choice a group where have more access to.'));
}
else {
oa_core_store_orphan_settings($node, array(
'og_orphans' => array(
'move' => array(
'group_type' => 'node',
'gid' => $gid,
),
),
));
}
}
else {
oa_core_store_orphan_settings($node, array(
'og_orphans' => array(
'delete' => $form_state['values']['oa_core_orphans'] == 'delete',
),
));
}
}
function oa_core_store_orphan_settings($node, $settings = NULL) {
$data =& drupal_static(__FUNCTION__, array());
if ($settings) {
$data[$node->nid] = $settings + (isset($data[$node->nid]) ? $data[$node->nid] : array());
}
return isset($data[$node->nid]) ? $data[$node->nid] : array();
}
function oa_core_node_delete($node) {
if ($settings = oa_core_store_orphan_settings($node)) {
foreach ($settings as $key => $value) {
$node->{$key} = $value;
}
}
_oa_core_node_delete($node);
}
function oa_core_get_orphans($group_type, $gid, $max = 1) {
$query = new EntityFieldQuery();
$result = $query
->entityCondition('entity_type', 'og_membership')
->propertyCondition('group_type', $group_type, '=')
->propertyCondition('gid', $gid, '=')
->propertyCondition('entity_type', 'user', '!=')
->propertyOrderBy('id')
->range(0, $max)
->execute();
return !empty($result['og_membership']) ? og_membership_load_multiple(array_keys($result['og_membership'])) : array();
}
function oa_core_node_prepare($node) {
if (empty($node->nid) && field_info_instance('node', OA_SPACE_FIELD, $node->type)) {
if (!empty($_GET['og_group_ref'])) {
$gid = $_GET['og_group_ref'];
}
else {
$gid = oa_core_get_space_context();
}
if ($gid && og_user_access('node', $gid, "create {$node->type} content")) {
$node->{OA_SPACE_FIELD}[LANGUAGE_NONE][0]['target_id'] = $gid;
}
}
}
function oa_core_views_pre_render(&$view) {
if ($view->name == 'oa_core_space_types') {
if (count($view->result) == 1) {
$args = $_GET;
unset($args['q']);
drupal_goto('node/add/oa-space/' . $view->result[0]->tid, array(
'query' => $args,
));
}
elseif (user_access('administer taxonomy')) {
$view->attachment_before = '<p>' . t('Manage existing <em>Space Blueprints</em> or add new ones by <a href="!url">administrating the taxonomy</a>.', array(
'!url' => url('admin/structure/taxonomy/space_type'),
)) . '</p>';
}
}
}
function oa_core_views_pre_build(&$view) {
if ($view->name == 'oa_recent_activity') {
$view->override_path = $_GET['q'];
}
}
function oa_core_preprocess_views_view_fields(&$vars) {
$vars['index'] = $vars['view']->row_index;
$vars['display'] = $vars['view']->current_display;
$vars['count'] = count($vars['view']->result);
foreach ($vars['fields'] as $id => $field) {
$vars[$id] = $field->content;
switch ($id) {
case 'timestamp':
$vars[$id . '_raw'] = $field->raw;
break;
case 'field_user_picture':
case 'picture':
if (!strip_tags($field->content, '<img>')) {
$vars[$id] = oa_core_get_user_picture_for_views_fields($field);
$vars['fields'][$id]->content = $vars[$id];
}
break;
}
}
}
function oa_core_get_user_picture_for_views_fields($field) {
$image_style = 'oa_small_thumbnail';
if (isset($field->handler->options['settings']['image_style'])) {
$image_style = $field->handler->options['settings']['image_style'];
}
if (isset($field->handler->options['image_style'])) {
$image_style = $field->handler->options['image_style'];
}
return oa_users_picture(NULL, $image_style);
}
function oa_users_picture($account = NULL, $image_style = 'oa_small_thumbnail', $url = FALSE) {
$pictures = module_invoke_all('oa_users_picture', $account, $image_style, $url);
return $pictures ? reset($pictures) : NULL;
}
function oa_core_replace_group(&$field, $context) {
if (isset($field)) {
if (isset($context['entity']->type) && $context['entity']->type == OA_SPACE_TYPE) {
$field = str_replace(t('group'), t('space'), $field);
$field = str_replace(t('Group'), t('Space'), $field);
}
}
}
function oa_core_field_attach_view_alter(&$output, $context) {
if ($context['entity_type'] == 'node') {
if (!empty($output['group_group'][0]['#title'])) {
oa_core_replace_group($output['group_group'][0]['#title'], $context);
}
if (!empty($output['group_group'][0]['#markup'])) {
oa_core_replace_group($output['group_group'][0]['#markup'], $context);
}
}
}
function oa_core_section_template() {
ctools_include('export-ui');
$handler = panelizer_entity_plugin_get_handler('node');
return panelizer_export_ui_switcher_page($handler, OA_SECTION_TYPE . '.page_manager', 'panelizer_defaults', 'list');
}
function oa_core_space_template() {
ctools_include('export-ui');
$handler = panelizer_entity_plugin_get_handler('node');
return panelizer_export_ui_switcher_page($handler, OA_SPACE_TYPE . '.page_manager', 'panelizer_defaults', 'list');
}
function oa_core_show_groups() {
drupal_goto('groups');
}
function oa_core_add_member_api($group_type, $gid, $uid, $override = FALSE) {
$account = user_load($uid);
$group = entity_load_single($group_type, $gid);
$label = entity_label($group_type, $group);
$entity_type = 'node';
$message = '';
$params = array();
$params['@user'] = format_username($account);
$params['@group'] = entity_access('view', $entity_type, $group) ? entity_label($entity_type, $group) : t('Private group');
if (!$uid) {
$dest = drupal_get_destination();
if (variable_get('user_register', 1)) {
$message = t('In order to join any group, you must <a href="!login">login</a>. After you have successfully done so, you will need to request membership again.', array(
'!login' => url("user/login", array(
'query' => $dest,
)),
));
}
else {
$message = t('In order to join any group, you must <a href="!login">login</a> or <a href="!register">register</a> a new account. After you have successfully done so, you will need to request membership again.', array(
'!register' => url("user/register", array(
'query' => $dest,
)),
'!login' => url("user/login", array(
'query' => $dest,
)),
));
}
}
elseif (!$override && og_is_member($entity_type, $gid, 'user', $account, array(
OG_STATE_BLOCKED,
))) {
$message = t('@user is blocked and cannot be addded.', $params);
}
elseif (!$override && og_is_member($entity_type, $gid, 'user', $account, array(
OG_STATE_PENDING,
))) {
$message = t('@user already has a pending membership for the the group @group.', $params);
}
elseif (og_is_member($entity_type, $gid, 'user', $account, array(
OG_STATE_ACTIVE,
))) {
$message = t('@user is already a member of the group @group.', $params);
}
if (empty($message)) {
og_ungroup('node', $group->nid, 'user', $account);
og_group('node', $group->nid, array(
'entity' => $account,
));
$message = t('%user has been added to the space %title.', array(
'%user' => format_username($account),
'%title' => $label,
));
}
drupal_set_message($message);
return $message;
}
function oa_core_add_member($group_type, $gid, $uid, $field_name = NULL, $type = 'nojs') {
global $user;
if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], $group_type . '_' . $gid . '_' . $uid)) {
return MENU_ACCESS_DENIED;
}
$account = user_load($uid);
$is_user = $user->uid == $account->uid && $user->uid != 1;
if (module_exists('og_ui') && $type != 'ajax' && $is_user) {
module_load_include('inc', 'og_ui', 'og_ui.pages');
if (og_user_access('node', $gid, 'subscribe', $account) || og_user_access('node', $gid, 'subscribe without approval', $account)) {
return drupal_get_form('og_ui_confirm_subscribe', 'node', $gid, $account, $field_name);
}
drupal_access_denied();
}
oa_core_add_member_api($group_type, $gid, $uid, !$is_user);
if ($type != 'ajax') {
drupal_goto();
}
else {
$commands = array();
$commands[] = ajax_command_append('#oa-core-messages', theme('status_messages'));
$page = array(
'#type' => 'ajax',
'#commands' => $commands,
);
ajax_deliver($page);
}
return NULL;
}
function oa_core_remove_member($group_type, $gid, $from_children, $uid, $type = 'nojs') {
if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], $group_type . '_' . $gid . '_' . $uid)) {
return MENU_ACCESS_DENIED;
}
$account = user_load($uid);
$group = entity_load_single($group_type, $gid);
$label = entity_label($group_type, $group);
$username = format_username($account);
og_ungroup('node', $group->nid, 'user', $account);
if ($from_children == 'all' && module_exists('oa_subspaces') && og_user_access('node', $group->nid, 'administer group') && ($children = og_subgroups_children_load('node', $group->nid)) && ($user_groups = og_get_entity_groups('user', $account))) {
if ($remove = og_subgroups_intersect_groups($children, $user_groups)) {
foreach ($remove as $entity_type => $ids) {
foreach ($ids as $id) {
$child_group = entity_load_single($entity_type, $id);
og_ungroup($entity_type, $id, 'user', $account);
$child_label = entity_label($entity_type, $child_group);
drupal_set_message(t('%user has been removed from child @type %title.', array(
'@type' => drupal_strtolower(node_type_get_name($child_group->type)),
'%user' => $username,
'%title' => $child_label,
)));
}
}
}
}
drupal_set_message(t('%user has been removed from the @type %title.', array(
'@type' => drupal_strtolower(node_type_get_name($group->type)),
'%user' => $username,
'%title' => $label,
)));
if ($type != 'ajax') {
drupal_goto();
}
else {
$commands = array();
$commands[] = ajax_command_append('#oa-core-messages', theme('status_messages'));
$page = array(
'#type' => 'ajax',
'#commands' => $commands,
);
ajax_deliver($page);
}
return NULL;
}
function oa_core_block_member($group_type, $gid, $uid, $type = 'nojs') {
if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], $group_type . '_' . $gid . '_' . $uid)) {
return MENU_ACCESS_DENIED;
}
$account = user_load($uid);
$group = entity_load_single($group_type, $gid);
$label = entity_label($group_type, $group);
og_ungroup('node', $group->nid, 'user', $account);
og_group('node', $group->nid, array(
'entity' => $account,
'state' => OG_STATE_BLOCKED,
));
drupal_set_message(t('%user has been blocked.', array(
'%user' => format_username($account),
'%title' => $label,
)));
if ($type != 'ajax') {
drupal_goto();
}
else {
$commands = array();
$commands[] = ajax_command_append('#oa-core-messages', theme('status_messages'));
$page = array(
'#type' => 'ajax',
'#commands' => $commands,
);
ajax_deliver($page);
}
return NULL;
}
function oa_core_add_admin($group_type, $gid, $uid, $type = 'nojs') {
if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], $group_type . '_' . $gid . '_' . $uid)) {
return MENU_ACCESS_DENIED;
}
$account = user_load($uid);
$group = entity_load_single($group_type, $gid);
$label = entity_label($group_type, $group);
$og_roles = og_roles($group_type, $group->type, $gid, FALSE, FALSE);
$rid = array_search(OG_ADMINISTRATOR_ROLE, $og_roles);
if ($rid > 0) {
og_role_grant($group_type, $gid, $uid, $rid);
og_invalidate_cache();
drupal_set_message(t('%user has been added as an Admin to the space %title.', array(
'%user' => format_username($account),
'%title' => $label,
)));
}
if ($type != 'ajax') {
drupal_goto();
}
else {
$commands = array();
$commands[] = ajax_command_append('#oa-core-messages', theme('status_messages'));
$page = array(
'#type' => 'ajax',
'#commands' => $commands,
);
ajax_deliver($page);
}
return NULL;
}
function oa_core_remove_admin($group_type, $gid, $uid, $type = 'nojs') {
if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], $group_type . '_' . $gid . '_' . $uid)) {
return MENU_ACCESS_DENIED;
}
$account = user_load($uid);
$group = entity_load_single($group_type, $gid);
$label = entity_label($group_type, $group);
$og_roles = og_roles($group_type, $group->type, $gid, FALSE, FALSE);
$rid = array_search(OG_ADMINISTRATOR_ROLE, $og_roles);
if ($rid > 0) {
og_role_revoke($group_type, $gid, $uid, $rid);
og_invalidate_cache();
drupal_set_message(t('%user has been removed as Admin of space %title.', array(
'%user' => format_username($account),
'%title' => $label,
)));
}
if ($type != 'ajax') {
drupal_goto();
}
else {
$commands = array();
$commands[] = ajax_command_append('#oa-core-messages', theme('status_messages'));
$page = array(
'#type' => 'ajax',
'#commands' => $commands,
);
ajax_deliver($page);
}
return NULL;
}
function oa_core_views_copy_get_arguments_to_link(&$view, $display_name = 'default', $field_name = 'name') {
$args = $_GET;
unset($args['q']);
if (count($args) > 0) {
$query = http_build_query($args);
if (!empty($view->display[$display_name]->handler->options['fields'][$field_name]['alter']['path'])) {
$view->display[$display_name]->handler->options['fields'][$field_name]['alter']['path'] .= '?' . $query;
}
}
}
function oa_core_views_pre_view(&$view) {
if ($view->name == 'open_atrium_content' && !empty($view->display_handler->options['pane_conf']['view_settings']) && $view->display_handler->options['pane_conf']['view_settings'] == 'table') {
$view->display_handler->options['defaults']['style_options'] = FALSE;
$view->display_handler->options['style_options'] = $view->display['page_1']->display_options['style_options'];
}
elseif ($view->name == 'oa_core_space_types') {
oa_core_views_copy_get_arguments_to_link($view);
}
if (!empty($view->display_handler->options['pane_conf']['exposed']['oa_core_default_to_current_user'])) {
global $user;
$exposed = $view
->get_exposed_input();
if (!isset($_GET['uid']) && empty($exposed['uid'])) {
$exposed['uid'] = $user->name;
}
$view
->set_exposed_input($exposed);
}
}
function oa_core_form_views_content_views_panes_content_type_edit_form_alter(&$form, &$form_state, $form_id) {
$conf = $form_state['conf'];
$pane = $form_state['pane'];
$group = oa_core_get_space_context();
if (isset($form['exposed']['filter-oa_parent_space_target_id']['oa_parent_space_target_id'])) {
$form['exposed']['filter-oa_parent_space_target_id']['oa_parent_space_target_id']['#options'] = array(
'' => t('- Active Group -'),
) + $form['exposed']['filter-oa_parent_space_target_id']['oa_parent_space_target_id']['#options'];
if (!isset($pane->configuration['exposed']['oa_parent_space_target_id'])) {
$pane->configuration['exposed']['oa_parent_space_target_id'] = '';
}
}
if (isset($form['exposed']['filter-og_group_ref_target_id']['og_group_ref_target_id'])) {
if (!isset($pane->configuration['exposed']['og_group_ref_target_id'])) {
$pane->configuration['exposed']['og_group_ref_target_id'] = '';
}
$form['exposed']['filter-og_group_ref_target_id']['og_group_ref_target_id_mine'] = array(
'#title' => t('Limit to groups of current user'),
'#type' => 'checkbox',
'#default_value' => !empty($conf['exposed']['og_group_ref_target_id_mine']),
'#parents' => array(
'exposed',
'og_group_ref_target_id_mine',
),
);
if (isset($form['exposed']['filter-og_group_ref_target_id']['og_group_ref_target_id']['#autocomplete_path'])) {
$form['exposed']['filter-og_group_ref_target_id']['og_group_ref_target_id']['#autocomplete_path'] = str_replace('oacoreselect2widget', 'oacoreselect2widgetpanes', $form['exposed']['filter-og_group_ref_target_id']['og_group_ref_target_id']['#autocomplete_path']);
$form['exposed']['filter-og_group_ref_target_id']['og_group_ref_target_id']['#oa_core_in_pane_config'] = TRUE;
}
$form['exposed']['filter-og_group_ref_target_id']['og_group_ref_target_id']['#states'] = array(
'visible' => array(
':input[name="exposed[og_group_ref_target_id_mine]"]' => array(
'checked' => FALSE,
),
),
);
$form['exposed']['filter-og_group_ref_target_id']['og_group_ref_target_id']['#after_build'][] = 'oa_core_adjust_og_group_ref_for_select2';
}
if (isset($form['exposed']['filter-oa_section_ref_target_id']['oa_section_ref_target_id'])) {
if (isset($form['exposed']['filter-og_group_ref_target_id']['og_group_ref_target_id'])) {
$form['buttons']['#process'] = array(
'oa_core_form_views_content_views_panes_content_type_edit_process',
'form_process_actions',
'form_process_container',
);
}
if (!empty($pane->configuration['exposed']['og_group_ref_target_id']) && !isset($_POST['exposed']['og_group_ref_target_id']) && $pane->configuration['exposed']['og_group_ref_target_id'] != $group && is_numeric($pane->configuration['exposed']['og_group_ref_target_id'])) {
_oa_sections_get_current_selected_space(NULL, $pane->configuration['exposed']['og_group_ref_target_id']);
}
$form['exposed']['filter-oa_section_ref_target_id']['oa_section_ref_target_id']['#after_build'][] = 'oa_core_refresh_section_values';
$form['exposed']['filter-oa_section_ref_target_id']['oa_section_ref_target_id']['#options'] = array(
'' => t('- Active Section -'),
) + $form['exposed']['filter-oa_section_ref_target_id']['oa_section_ref_target_id']['#options'];
if (!isset($pane->configuration['exposed']['oa_section_ref_target_id'])) {
$pane->configuration['exposed']['oa_section_ref_target_id'] = '';
}
}
if (!empty($form['exposed']['filter-uid'])) {
$form['exposed']['filter-uid']['oa_core_default_to_current_user'] = array(
'#type' => 'checkbox',
'#title' => t('Default to current user'),
'#parents' => array(
'exposed',
'oa_core_default_to_current_user',
),
'#default_value' => !empty($conf['exposed']['oa_core_default_to_current_user']),
);
$form['exposed']['filter-uid']['uid']['#states'] = array(
'visible' => array(
':input[name="exposed[oa_core_default_to_current_user]"]' => array(
'checked' => FALSE,
),
),
);
}
if (isset($form['show_exposed_form'])) {
$form['show_exposed_form']['#default_value'] = isset($form_state['conf']['show_exposed_form']) ? $form_state['conf']['show_exposed_form'] : FALSE;
$form['display_settings']['show_exposed_form'] = $form['show_exposed_form'];
$form['display_settings']['show_exposed_form']['#weight'] = 10;
unset($form['show_exposed_form']);
if (!isset($pane->configuration['show_exposed_form'])) {
$pane->configuration['show_exposed_form'] = FALSE;
}
}
}
function oa_core_adjust_og_group_ref_for_select2($element) {
$form_state = array();
oa_core_select2widget_entity_validate_field($element, $form_state, array());
if (isset($element['#attributes']['class'])) {
foreach ($element['#attributes']['class'] as $key => $value) {
$element['#attributes']['class'][$key] = str_replace($value, 'ctools-auto-submit-exclude', '');
}
}
return $element;
}
function oa_core_refresh_section_values($element) {
$element['#options'] = array_intersect_key($element['#options'], array(
NULL => '',
'All' => '',
));
$values = entityreference_get_selection_handler(field_info_field('oa_section_ref'))
->getReferencableEntities();
if ($values) {
$element['#options'] += current($values);
}
if ($element['#value'] && !array_key_exists($element['#value'], $element['#options'])) {
$element['#value'] = 'All';
}
return $element;
}
function oa_core_form_views_content_views_panes_content_type_edit_process($element, &$form_state) {
if (isset($form_state['complete form']['content_settings']['view_mode']['#default_value']) && !in_array($form_state['complete form']['content_settings']['view_mode']['#default_value'], array_keys($form_state['complete form']['content_settings']['view_mode']['#options']))) {
$form_state['complete form']['content_settings']['view_mode']['#default_value'] = current(array_keys($form_state['complete form']['content_settings']['view_mode']['#options']));
}
if (isset($element['preview']['#ajax'])) {
$element['preview']['#ajax']['callback'] = 'oa_core_refresh_oa_section_ref_target_id';
}
return $element;
}
function oa_core_refresh_oa_section_ref_target_id($form, $form_state) {
$messages = theme('status_messages');
$messages = $messages ? $messages : '';
$return = array(
'#type' => 'ajax',
'#commands' => array(),
);
$return['#commands'][] = ajax_command_replace('#panopoly-form-widget-preview', $messages . panopoly_magic_ajax_update_preview($form, $form_state));
if (isset($form['exposed']['filter-oa_section_ref_target_id']['oa_section_ref_target_id'])) {
$form['exposed']['filter-oa_section_ref_target_id']['oa_section_ref_target_id']['#theme_wrappers'] = array();
$form['exposed']['filter-oa_section_ref_target_id']['oa_section_ref_target_id']['#attributes']['id'] = 'edit-exposed-oa-section-ref-target-id';
$return['#commands'][] = ajax_command_replace('#edit-exposed-oa-section-ref-target-id', drupal_render($form['exposed']['filter-oa_section_ref_target_id']['oa_section_ref_target_id']));
}
return $return;
}
function _oa_core_set_default_value_for_view($name) {
return in_array($name, array(
'open_atrium_content',
'oa_recent_activity',
));
}
function oa_core_form_views_exposed_form_alter(&$form, &$form_state) {
if (_oa_core_set_default_value_for_view($form_state['view']->name) && $form_state['view']->display_handler
->get_url() != $_GET['q']) {
$form['#action'] = url($_GET['q']);
}
if (!empty($form['og_group_ref_target_id'])) {
$form['#after_build'][] = 'oa_core_views_exposed_form_rearrange';
}
if (!empty($form_state['input']['og_group_ref_target_id']) && !empty($form['oa_section_ref_target_id'])) {
$view = $form_state['view'];
$exposed_form_overrides = $view->display_handler
->get_option('exposed_form_overrides');
$pane_conf = $view->display_handler
->get_option('pane_conf');
$bypass_access = FALSE;
if (isset($exposed_form_overrides['filters']['oa_section_ref_target_id'])) {
if (empty($exposed_form_overrides['filters']['oa_section_ref_target_id']) || isset($pane_conf['show_exposed_form']) && empty($pane_conf['show_exposed_form'])) {
$bypass_access = TRUE;
}
}
$space_id = str_replace(OA_SPACE_CURRENT, oa_core_get_space_context(), $form_state['input']['og_group_ref_target_id']);
$include_archived = user_access('view trash content') || is_numeric($space_id) && og_user_access('node', $space_id, 'view trash content', NULL, FALSE, TRUE);
$sections = array(
'' => t('- Active Section -'),
'All' => t('- Any -'),
);
if (is_numeric($space_id)) {
$sections += oa_core_space_sections($space_id, NULL, $bypass_access, array(), $include_archived);
}
$form['oa_section_ref_target_id']['#options'] = $sections;
}
}
function oa_core_views_exposed_form_rearrange($form) {
if (!empty($form['og_group_ref_target_id_mine']) || !empty($form['og_subspaces_view_all'])) {
$form['og_group_ref_target_id'] = array(
'og_group_ref_target_id' => $form['og_group_ref_target_id'],
);
if (!empty($form['og_group_ref_target_id_mine'])) {
$form['og_group_ref_target_id']['og_group_ref_target_id_mine'] = $form['og_group_ref_target_id_mine'];
unset($form['og_group_ref_target_id_mine']);
}
if (!empty($form['og_subspaces_view_all'])) {
$form['og_group_ref_target_id']['og_subspaces_view_all'] = $form['og_subspaces_view_all'];
unset($form['og_subspaces_view_all']);
}
if (!empty($form['og_subspaces_view_parent'])) {
$form['og_group_ref_target_id']['og_subspaces_view_parent'] = $form['og_subspaces_view_parent'];
unset($form['og_subspaces_view_parent']);
}
}
return $form;
}
function oa_core_token_info() {
$node['group-or-section-alias'] = array(
'name' => t("URL"),
'description' => t("The alias to the section (or group if no section of given content.)"),
);
return array(
'tokens' => array(
'node' => $node,
),
);
}
function oa_core_get_alias($nid, $languagecode = NULL) {
$cache =& drupal_static('oa_core_alias', array());
$cachekey = $nid . ':' . $languagecode;
if (isset($cache[$cachekey])) {
return $cache[$cachekey];
}
if ($node = node_load($nid)) {
$uri = entity_uri('node', $node);
$path = drupal_get_path_alias($uri['path'], $languagecode);
if (!isset($node->path['pathauto'])) {
module_load_include('inc', 'pathauto');
$path = pathauto_create_alias('node', 'return', $uri['path'], array(
'node' => $node,
), $node->type, $languagecode);
}
$cache[$cachekey] = $path;
}
else {
$cache[$cachekey] = FALSE;
}
return $cache[$cachekey];
}
function oa_core_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
if ($type == 'node' && !empty($data['node']) && isset($tokens['group-or-section-alias'])) {
$node = $data['node'];
$original = $tokens['group-or-section-alias'];
$section = field_get_items('node', $node, OA_SECTION_FIELD);
$space = field_get_items('node', $node, OA_SPACE_FIELD);
$section_id = !empty($section[0]['target_id']) ? $section[0]['target_id'] : 0;
$space_id = !empty($space[0]['target_id']) ? $space[0]['target_id'] : 0;
$default_path_alias = variable_get('oa_default_path_alias', 'content');
$languagecode = isset($options['language']) ? $options['language']->language : NULL;
if ($section_id && node_load($section_id)) {
$path = drupal_get_path_alias('node/' . $section_id, $languagecode);
if (module_exists('pathauto') && preg_match('#^node/(\\d+)#', $path)) {
$path = oa_core_get_alias($section_id, $languagecode);
}
if (!empty($path)) {
$replacements[$original] = $path;
}
}
elseif ($space_id && node_load($space_id)) {
$path = drupal_get_path_alias('node/' . $space_id, $languagecode);
if (module_exists('pathauto') && preg_match('#^node/(\\d+)#', $path)) {
$path = oa_core_get_alias($space_id, $languagecode);
}
if (!empty($path)) {
$replacements[$original] = $path;
if ($node->type != OA_SECTION_TYPE) {
$replacements[$original] .= "/{$default_path_alias}";
}
}
}
else {
$replacements[$original] = $default_path_alias;
}
}
return $replacements;
}
function oa_core_preprocess_views_exposed_form(&$vars) {
$vars['collapsed_filter'] = empty($vars['form']['#collapsed_filter']) ? FALSE : TRUE;
}
function oa_core_get_allowed_space_types($field) {
$options = array();
$gid = oa_core_get_space_context();
if (!$gid || !module_exists('oa_subspaces') || user_access('administer group') || user_access('create oa_space content') || og_user_access('node', $gid, 'use any oa button space_type')) {
return taxonomy_allowed_values($field);
}
if ($gid) {
foreach ($field['settings']['allowed_values'] as $tree) {
$options = $options + oa_core_get_allowed_space_terms($gid, $tree['vocabulary']);
}
}
return $options;
}
function oa_core_get_allowed_space_terms($gid = NULL, $vocab_name = 'space_type') {
global $user;
$gid = isset($gid) ? $gid : oa_core_get_space_context();
$tids = array();
if (!$gid || !module_exists('oa_subspaces') || user_access('administer group') || user_access('create oa_space content') || og_user_access('node', $gid, 'use any oa button space_type', NULL, FALSE, TRUE)) {
return NULL;
}
if ($gid && $user->uid) {
if ($vocabulary = oa_core_taxonomy_vocabulary($vocab_name)) {
if ($terms = taxonomy_get_tree($vocabulary->vid)) {
foreach ($terms as $term) {
if (oa_core_get_taxonomy_term_access($term->tid, $gid, $vocab_name)) {
$tids[$term->tid] = str_repeat('-', $term->depth) . $term->name;
}
}
}
}
}
return $tids;
}
function oa_core_get_space_type_options($vocab_name = 'space_type') {
$query = db_select('taxonomy_term_data', 'td');
$query
->join('taxonomy_vocabulary', 'v', 'v.vid = td.vid');
$query
->fields('td', array(
'tid',
))
->condition('v.machine_name', $vocab_name);
$terms = taxonomy_term_load_multiple($query
->execute()
->fetchCol());
$options = array();
foreach ($terms as $term) {
$options[$term->tid] = module_invoke_all('oa_core_space_type_options', $term, $vocab_name);
}
drupal_alter('oa_core_space_type_options', $options, $vocab_name);
return $options;
}
function oa_core_oa_core_space_type_options($term, $vocab_name) {
$layout = field_get_items('taxonomy_term', $term, 'field_oa_section_layout', LANGUAGE_NONE);
return array(
'layout' => $layout[0]['value'],
);
}
function _oa_core_hide_comment_settings(&$form) {
$node = $form['#node'];
if (isset($form['comment_settings']) && (empty($node->type) || variable_get('comment_' . $node->type, COMMENT_NODE_OPEN) == COMMENT_NODE_HIDDEN) && (empty($node->nid) || $node->comment == COMMENT_NODE_HIDDEN || $node->comment == COMMENT_NODE_CLOSED && empty($node->comment_count))) {
$form['comment_settings']['#access'] = FALSE;
}
}
function oa_core_panelizer_pre_render_alter(&$panelizer, $display, $entity) {
if (module_exists('comment')) {
if (isset($entity->comment) && $entity->comment == COMMENT_NODE_HIDDEN) {
foreach ($panelizer->display->content as $key => $display) {
if ($display->type == 'node_comment_wrapper') {
unset($panelizer->display->content[$key]);
}
}
}
}
}
function _oa_core_setup_node_space_type(&$form, $type = 'space_type', $field_name = 'field_oa_space_type') {
$selector = 'select[name="' . $field_name . '[und]"]';
$space_type = !empty($form[$field_name]['und']['#default_value']) ? $form[$field_name]['und']['#default_value'][0] : NULL;
$form['panelizer']['#states'] = array(
'visible' => array(
':input[name="field_oa_section_override[und]"]' => array(
'checked' => TRUE,
),
),
'invisible' => array(
':input[name="field_oa_section_override[und]"]' => array(
'checked' => FALSE,
),
),
);
$form['panelizer']['#access'] = TRUE;
$options = oa_core_get_space_type_options($type);
$js_options = array();
foreach ($options as $tid => $item) {
$js_options['tid' . $tid] = $item;
}
$form['#attached']['js'][] = array(
'data' => array(
'oaCoreSpaceTypeOptions' => $js_options,
'oaCoreSpaceTypeSelector' => $selector,
'oaCoreSpaceType' => $space_type,
),
'type' => 'setting',
);
$form['#attached']['js'][] = array(
'data' => drupal_get_path('module', 'oa_core') . '/js/oa_core_space_type.js',
'type' => 'file',
);
}
function oa_core_form_oa_space_node_form_alter(&$form, &$form_state, &$form_id) {
if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'oa-space' && ($space_tid = arg(3)) && !empty($space_tid)) {
$form['field_oa_space_type']['und']['#default_value'] = array(
$space_tid,
);
$form['field_oa_space_type']['#access'] = FALSE;
}
_oa_core_hide_comment_settings($form);
_oa_core_setup_node_space_type($form);
}
function oa_core_form_oa_group_node_form_alter(&$form, &$form_state, &$form_id) {
_oa_core_hide_comment_settings($form);
}
function oa_core_get_space_type_layout_options($bundle) {
$plugins = panelizer_get_entity_plugins();
$node_plugin = panelizer_entity_plugin_get_handler($plugins['node']);
$options = array();
foreach ($node_plugin->plugin['view modes'] as $view_mode => $view_mode_info) {
$view_bundle = $bundle . '.' . $view_mode;
if (!$node_plugin
->has_panel_choice($view_bundle)) {
continue;
}
$panelizers = $node_plugin
->get_default_panelizer_objects($view_bundle);
foreach ($panelizers as $name => $panelizer) {
if (empty($panelizer->disabled)) {
$options[$name] = $panelizer->title ? $panelizer->title : t('Default');
if (!empty($panelizer->title)) {
$thisarray = explode(':', $name);
if (!empty($thisarray[3])) {
$options[$name] = ucfirst($thisarray[3]) . ':' . $options[$name];
}
}
}
}
if (!$node_plugin
->has_default_panel($view_bundle)) {
$options = array(
'' => t('-- No panel --'),
) + $options;
}
}
return $options;
}
function _oa_core_setup_taxonomy_space_type(&$form, $layout_bundle = 'oa_space') {
$term = (object) $form['#term'];
$layout = field_get_items('taxonomy_term', $term, 'field_oa_section_layout', LANGUAGE_NONE);
$layout_defaults = array();
if (!empty($layout[0]['value'])) {
$layout_defaults[] = $layout[0]['value'];
}
$section_layouts = oa_core_get_space_type_layout_options($layout_bundle);
if (isset($form['field_oa_section_layout'])) {
$form['field_oa_section_layout'][$form['field_oa_section_layout']['#language']]['#options'] = $section_layouts;
$form['field_oa_section_layout'][$form['field_oa_section_layout']['#language']]['#default_value'] = $layout_defaults;
}
}
function oa_core_form_taxonomy_form_term_alter(&$form, &$form_state, $form_id) {
if ($form['#vocabulary']->machine_name == 'space_type') {
_oa_core_setup_taxonomy_space_type($form);
}
}
function oa_core_node_delete_redirect($form, &$form_state) {
$id = oa_core_get_section_context();
if (empty($id)) {
$id = oa_core_get_space_context();
}
if (!empty($form['#node'])) {
if (in_array($form['#node']->type, array(
OA_SPACE_TYPE,
OA_GROUP_TYPE,
)) && module_exists('oa_subspaces') && !empty($form['#node']->{OA_PARENT_SPACE}[LANGUAGE_NONE][0]['target_id'])) {
$id = $form['#node']->{OA_PARENT_SPACE}[LANGUAGE_NONE][0]['target_id'];
}
elseif ($form['#node']->type == OA_SECTION_TYPE) {
$id = oa_core_get_space_context();
}
if ($id == $form['#node']->nid) {
$id = NULL;
}
}
if (!empty($id)) {
$form_state['redirect'] = 'node/' . $id;
}
}
function oa_core_view_query_modify_condition(&$query, $columns, $ids) {
if (empty($ids)) {
return;
}
if (!is_array($columns)) {
$columns = array(
$columns,
);
}
foreach (array_keys($query->where) as $where_group) {
foreach ($query->where[$where_group]['conditions'] as $key => &$condition) {
foreach ($columns as $column) {
oa_core_view_query_modify_condition_object($condition, $column, $ids);
}
}
unset($condition);
}
}
function oa_core_view_query_modify_condition_object(&$condition, $column, $ids) {
if (is_object($condition['field']) && is_a($condition['field'], 'DatabaseCondition')) {
$conditions = $condition['field']
->conditions();
$new_subquery = new DatabaseCondition($conditions['#conjunction']);
foreach ($conditions as $key => $inner_condition) {
if (is_numeric($key)) {
oa_core_view_query_modify_condition_object($inner_condition, $column, $ids);
$new_subquery
->condition($inner_condition['field'], $inner_condition['value'], $inner_condition['operator']);
}
}
$condition['field'] = $new_subquery;
}
elseif ($condition['field'] === $column || is_string($condition['field']) && substr($condition['field'], -strlen($column) - 2) === "__{$column}") {
$value = $condition['value'];
if (!is_array($value)) {
$value = array(
$value,
);
$condition['operator'] = 'IN';
}
$condition['value'] = array_merge($value, $ids);
}
}
function oa_core_views_query_alter(&$view, &$query) {
if ($view->name == 'oa_core_space_types') {
$tids = oa_core_get_allowed_space_terms();
if (isset($tids)) {
$tids = array_keys($tids);
$query
->add_where(1, 'taxonomy_term_data.tid', $tids, 'IN');
}
}
if (!empty($view->exposed_input['og_group_ref_target_id']) && is_numeric($view->exposed_input['og_group_ref_target_id']) && !empty($view->filter['og_group_ref_target_id']->options['exposed'])) {
$join = new views_join();
$join
->construct('field_data_oa_other_spaces_ref', 'node', 'nid', 'entity_id', array(
array(
'field' => 'entity_type',
'value' => 'node',
),
array(
'field' => 'deleted',
'value' => 0,
'numeric' => TRUE,
),
));
$alias = $query
->ensure_table('field_data_oa_other_spaces_ref', 'node', $join);
if ($alias) {
$extra_groups = array();
$group = $query
->set_where_group('OR');
foreach ($query->where[1]['conditions'] as $key => $condition) {
$column = 'og_membership';
if (!empty($condition['field']) && is_string($condition['field']) && ($condition['field'] === $column || $condition['field'] === $column . ".gid" || substr($condition['field'], -strlen($column) - 2) === "__{$column}")) {
$sub_condition = db_or()
->condition("{$alias}.delta", NULL, 'IS NULL')
->condition("{$alias}.delta", 0);
$new_condition = db_and()
->condition($condition['field'], $condition['value'], $condition['operator'])
->condition($sub_condition);
$query
->add_where($group, $new_condition);
$extra_groups[] = $condition['value'];
unset($query->where[1]['conditions'][$key]);
break;
}
}
if (!empty($extra_groups)) {
$query
->add_where($group, "{$alias}.oa_other_spaces_ref_target_id", $extra_groups, 'IN');
if (module_exists('oa_subspaces') && !empty($view->exposed_input['oa_section_ref_target_id']) && is_numeric($view->exposed_input['oa_section_ref_target_id']) && !empty($view->filter['oa_section_ref_target_id']->options['exposed'])) {
$columns = array(
'field_data_oa_section_ref.oa_section_ref_target_id',
);
$extra_sections = oa_subspaces_matching_sections($view->exposed_input['oa_section_ref_target_id'], array(), $extra_groups);
oa_core_view_query_modify_condition($query, $columns, $extra_sections);
}
}
}
}
}
function oa_core_oa_related_allowed_default() {
return array(
OA_SECTION_TYPE,
OA_SPACE_TYPE,
);
}
function oa_core_process_exposed_group_input($filter) {
$options_exposed = !empty($filter->options['expose']) ? array_filter($filter->options['expose']) : array();
if (empty($options_exposed['oa_core_no_auto'])) {
$exposed = $filter->view
->get_exposed_input();
$id = !empty($options_exposed['identifier']) ? $options_exposed['identifier'] : 'og_group_ref';
if (isset($exposed[$id]) && (empty($exposed[$id]) || $exposed[$id] == OA_SPACE_CURRENT)) {
if ($group = oa_core_get_space_context()) {
$exposed[$id] = $group;
}
else {
unset($exposed[$id]);
}
}
if (!empty($_GET[$id . '_mine'])) {
$exposed[$id . '_mine'] = 1;
}
if (isset($exposed[$id . '_mine']) && empty($exposed[$id . '_mine'])) {
$exposed[$id . '_mine'] = FALSE;
}
global $user;
if (!empty($exposed[$id . '_mine'])) {
$groups = oa_core_get_groups_by_user($user, 'node');
if ($groups && ($gids = array_intersect_key($groups, $filter
->get_value_options()))) {
$exposed[$id] = $gids;
$filter->options['expose']['multiple'] = TRUE;
}
else {
return FALSE;
}
}
elseif (empty($options_exposed['multiple']) && isset($exposed[$id]) && is_array($exposed[$id])) {
unset($exposed[$id]);
}
$filter->view
->set_exposed_input($exposed);
}
return TRUE;
}
function oa_core_panelizer_defaults_override_alter(&$data) {
drupal_alter('oa_core_layout', $data);
$info = module_invoke_all('oa_core_add_panes');
foreach ($info as $panelizer => $panes) {
if (isset($data[$panelizer]->display)) {
foreach ($panes as $uuid => $pane) {
$pid = 'new-' . $uuid;
if (empty($pane)) {
if (isset($data[$panelizer]->display->content[$pid])) {
unset($data[$panelizer]->display->content[$pid]);
}
}
else {
$pane = $pane + array(
'shown' => TRUE,
'access' => array(),
'configuration' => array(),
'cache' => array(),
'style' => array(
'settings' => NULL,
),
'css' => array(),
'extras' => array(),
'position' => 9,
'locks' => array(),
'uuid' => $uuid,
'pid' => $pid,
);
if (isset($data[$panelizer])) {
$data[$panelizer]->display->content[$pid] = (object) $pane;
}
}
}
}
}
_oa_core_panelizer_sort($data);
}
function oa_core_default_page_manager_handlers_alter(&$data) {
drupal_alter('oa_core_layout', $data);
$info = module_invoke_all('oa_core_add_panes');
foreach ($info as $panelizer => $panes) {
if (isset($data[$panelizer]->conf['display'])) {
foreach ($panes as $uuid => $pane) {
$pid = 'new-' . $uuid;
if (empty($pane)) {
if (isset($data[$panelizer]->conf['display']->content[$pid])) {
unset($data[$panelizer]->conf['display']->content[$pid]);
}
}
else {
$pane = $pane + array(
'shown' => TRUE,
'access' => array(),
'configuration' => array(),
'cache' => array(),
'style' => array(
'settings' => NULL,
),
'css' => array(),
'extras' => array(),
'position' => 9,
'locks' => array(),
'uuid' => $uuid,
'pid' => $pid,
);
if (isset($data[$panelizer])) {
$data[$panelizer]->conf['display']->content[$pid] = (object) $pane;
}
}
}
}
}
_oa_core_panels_sort($data);
}
function oa_core_default_panels_mini_alter(&$data) {
drupal_alter('oa_core_layout', $data);
$info = module_invoke_all('oa_core_add_panes');
foreach ($info as $panelizer => $panes) {
if (isset($data[$panelizer]->display)) {
foreach ($panes as $uuid => $pane) {
$pid = 'new-' . $uuid;
if (empty($pane)) {
if (isset($data[$panelizer]->display->content[$pid])) {
unset($data[$panelizer]->display->content[$pid]);
}
}
else {
$pane = $pane + array(
'shown' => TRUE,
'access' => array(),
'configuration' => array(),
'cache' => array(),
'style' => array(
'settings' => NULL,
),
'css' => array(),
'extras' => array(),
'position' => 9,
'locks' => array(),
'uuid' => $uuid,
'pid' => $pid,
);
if (isset($data[$panelizer])) {
$data[$panelizer]->display->content[$pid] = (object) $pane;
}
}
}
}
}
_oa_core_panelizer_sort($data);
}
function _oa_core_panelizer_sort(&$data) {
foreach ($data as $key => $panel) {
$regions = array();
if (isset($panel->display)) {
foreach ($panel->display->content as $pid => $pane) {
$regions[$pane->panel][$pid] = $pane->position;
}
$data[$key]->display->panels = array();
foreach ($regions as $region => $panels) {
asort($panels);
$data[$key]->display->panels[$region] = array_keys($panels);
foreach ($data[$key]->display->panels[$region] as $index => $pid) {
$data[$key]->display->content[$pid]->position = $index;
}
}
}
}
}
function _oa_core_panels_sort(&$data) {
foreach ($data as $key => $panel) {
$regions = array();
if (isset($panel->conf['display'])) {
foreach ($panel->conf['display']->content as $pid => $pane) {
$regions[$pane->panel][$pid] = $pane->position;
}
$data[$key]->conf['display']->panels = array();
foreach ($regions as $region => $panels) {
asort($panels);
$data[$key]->conf['display']->panels[$region] = array_keys($panels);
foreach ($data[$key]->conf['display']->panels[$region] as $index => $pid) {
$data[$key]->conf['display']->content[$pid]->position = $index;
}
}
}
}
}
function _oa_core_change_panel_layout(&$data, $key, $new_layout, $default_region, $region_map = array()) {
if (!empty($data[$key])) {
$data[$key]->display->layout = $new_layout;
foreach ($data[$key]->display->panels as $region => $panels) {
$new_region = isset($region_map[$region]) ? $region_map[$region] : $default_region;
$data[$key]->display->panels[$new_region] = $panels;
unset($data[$key]->display->panels[$region]);
}
foreach ($data[$key]->display->content as $pid => $pane) {
$new_region = isset($region_map[$pane->panel]) ? $region_map[$pane->panel] : $default_region;
$data[$key]->display->content[$pid]->panel = $new_region;
}
if (!empty($data[$key]->display->panel_settings['style_settings'])) {
foreach ($data[$key]->display->panel_settings['style_settings'] as $region => $settings) {
$new_region = isset($region_map[$region]) ? $region_map[$region] : $default_region;
$data[$key]->display->panel_settings['style_settings'][$new_region] = $settings;
unset($data[$key]->display->panel_settings['style_settings'][$region]);
}
}
}
}
function oa_core_field_display_alter(&$display, $context) {
if ($display['type'] == 'og_vocab') {
$display['label'] = 'hidden';
}
}
function oa_core_collapse_filter($form) {
$result = TRUE;
if (!empty($_GET)) {
foreach ($_GET as $key => $value) {
if (isset($form[$key]['#type'])) {
$result = FALSE;
break;
}
}
}
return $result;
}
function oa_core_form_file_entity_settings_form_alter(&$form, &$form_state) {
$form['#submit'][] = 'oa_core_file_entity_settings_form_submit';
}
function oa_core_file_entity_settings_form_submit($form, $form_state) {
if ($form_state['values']['file_entity_default_allowed_extensions'] != $form['file_entity_default_allowed_extensions']['#default_value']) {
variable_set('file_entity_default_allowed_extensions', $form_state['values']['file_entity_default_allowed_extensions']);
oa_core_update_field_instances($form['file_entity_default_allowed_extensions']['#default_value']);
}
}
function oa_core_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
$field = $form['#field'];
$file_fields = array(
'fieldable_panels_pane-basic_file-field_basic_file_file',
'field_oa_media',
);
if (isset($form['instance']['settings']['file_extensions']) && in_array($field['field_name'], $file_fields)) {
$file_extensions = variable_get('file_entity_default_allowed_extensions', OA_FILE_EXTENSIONS_DEFAULT);
$form['instance']['settings']['file_extensions']['#description'] .= '<br>Leave blank for default: ' . $file_extensions;
$form['instance']['settings']['file_extensions']['#required'] = FALSE;
$form['#validate'][] = 'oa_core_field_ui_field_edit_form_validate';
}
}
function oa_core_field_ui_field_edit_form_validate($form, &$form_state) {
if (isset($form_state['values']['instance']['settings']['file_extensions'])) {
if (empty($form_state['values']['instance']['settings']['file_extensions'])) {
$form_state['values']['instance']['settings']['file_extensions'] = variable_get('file_entity_default_allowed_extensions', OA_FILE_EXTENSIONS_DEFAULT);
}
}
}
function _oa_core_is_default_allowed_extensions($extensions) {
static $media_extensions = '';
if (empty($media_extensions)) {
$media_file_extensions = explode(' ', variable_get('media__file_extensions'));
$file_entity_file_extensions = explode(' ', variable_get('file_entity_default_allowed_extensions', 'jpg jpeg gif png txt doc docx xls xlsx pdf ppt pptx pps ppsx odt ods odp mp3 mov mp4 m4a m4v mpeg avi ogg oga ogv weba webp webm'));
$combined_file_extensions = array_unique(array_merge($file_entity_file_extensions, $media_file_extensions));
$media_extensions = implode(' ', $combined_file_extensions);
}
return empty($extensions) || $extensions == $media_extensions || $extensions == PANOPOLY_WIDGETS_FILE_EXTENSIONS_DEFAULT || $extensions == OA_OLD_FILE_EXTENSIONS_DEFAULT;
}
function oa_core_field_default_field_instances_alter(&$instances) {
$file_fields = array(
'fieldable_panels_pane-basic_file-field_basic_file_file',
'field_oa_media',
);
foreach ($instances as $key => $instance) {
list($entity_type, $bundle, $fieldname) = explode('-', $key);
if (in_array($fieldname, $file_fields)) {
$current_extensions = $instance['settings']['file_extensions'];
$file_extensions = variable_get('file_entity_default_allowed_extensions', OA_FILE_EXTENSIONS_DEFAULT);
if (_oa_core_is_default_allowed_extensions($file_extensions)) {
$file_extensions = OA_FILE_EXTENSIONS_DEFAULT;
}
if (_oa_core_is_default_allowed_extensions($current_extensions)) {
$instances[$key]['settings']['file_extensions'] = $file_extensions;
}
}
}
}
function oa_core_update_field_instances($old_extensions = '') {
$instances = field_info_instances();
$file_fields = array(
'fieldable_panels_pane-basic_file-field_basic_file_file',
'field_oa_media',
);
foreach ($instances as $field_instance) {
foreach ($field_instance as $bundle) {
foreach ($bundle as $fieldname => $instance) {
if (in_array($fieldname, $file_fields)) {
$current_extensions = $instance['settings']['file_extensions'];
$file_extensions = variable_get('file_entity_default_allowed_extensions', OA_FILE_EXTENSIONS_DEFAULT);
if (_oa_core_is_default_allowed_extensions($file_extensions)) {
$file_extensions = OA_FILE_EXTENSIONS_DEFAULT;
}
if ($current_extensions == $old_extensions || _oa_core_is_default_allowed_extensions($current_extensions)) {
$instance['settings']['file_extensions'] = $file_extensions;
field_update_instance($instance);
}
}
}
}
}
}
function _oa_core_bootstrap_library_javascript_alter(&$js, $weight) {
foreach ($js as $js_file => $options) {
if (!is_array($options)) {
unset($js[$js_file]);
$js_file = $options;
$options = array();
}
$options['group'] = JS_LIBRARY;
$options['weight'] = $weight;
$js[$js_file] = $options;
}
}
function oa_core_libraries_info_alter(&$libraries) {
if (isset($libraries['bootstrap'])) {
unset($libraries['bootstrap']['files']['css']);
$jquery_ui_library = drupal_get_library('system', 'ui');
$jquery_ui_js = reset($jquery_ui_library['js']);
$weight = $jquery_ui_js['weight'] - 1;
_oa_core_bootstrap_library_javascript_alter($libraries['bootstrap']['files']['js'], $weight);
_oa_core_bootstrap_library_javascript_alter($libraries['bootstrap']['variants']['js']['files']['js'], $weight);
}
}