View source
<?php
function og_panels_help($section) {
switch ($section) {
case 'admin/help#og_panels':
return t('After enabling this module, visit the new Pages tab on any group. There, group admins may create as many pages as desired for their group. The pages may contain any layout that the site offers and admins may arrange many different types of content as desired. Site admins can restrict the types of content that may be added on the <a href="!settings">og_panels settings</a> page. You might want to make some Views available using <a href="!apv">admin/panels/views</a>. Group admins may designate one page as their group home page.', array(
'!settings' => url('admin/og/og_panels'),
'!apv' => url('admin/panels/views'),
));
case arg(0) == 'node' && arg(2) == 'og_panels' && !arg(3):
return '<p>' . t('Create custom pages for your group. Use custom pages to organize your content in a pretty and informative manner. Your group can group to be a whole website within a web site. Each custom page becomes a tab when viewing your group. One of your custom pages should be designated as your <em>group home page</em>. That page will then display when visitors first arrive at your group.') . '</p><p>' . t('Start by clicking the <a href="!url">Add new page</a> tab. Then you will choose a custom layout for your page. Then you will want to <em>edit content</em> for your custom page.', array(
'!url' => url('node/' . arg(1) . '/og_panels/form'),
)) . '</p>';
}
}
function og_panels_menu($may_cache) {
if ($may_cache) {
$items[] = array(
'path' => 'admin/og/og_panels',
'title' => t('Organic groups panels'),
'description' => t('Configure the content that is available to group admins when creating group pages.'),
'callback' => 'og_panels_admin_content',
'access' => user_access('administer organic groups'),
);
}
else {
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
if (og_is_group_type($node->type) && node_access('view', $node)) {
$nid = arg(1);
$items[] = array(
'path' => "node/{$nid}/og_panels",
'title' => t('Pages'),
'callback' => 'og_panels_overview',
'callback arguments' => array(
$node,
),
'access' => og_is_node_admin($node) && user_access('manage OG panels pages'),
'type' => MENU_LOCAL_TASK,
'weight' => 8,
);
$items[] = array(
'path' => "node/{$nid}/og_panels/list",
'title' => t('List'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items[] = array(
'path' => "node/{$nid}/og_panels/form",
'callback' => 'drupal_get_form',
'callback arguments' => array(
'og_panels_form',
$node,
),
'title' => arg(4) ? t('Edit page') : t('Add new page'),
'type' => MENU_LOCAL_TASK,
'weight' => 0,
);
$displays = og_panels_get_all($node->nid);
foreach ($displays as $display) {
if ($display->default_page && $display->published && arg(2) != 'feed') {
$items[] = array(
'path' => "node/{$nid}",
'title' => $node->title,
'callback' => 'og_panels_page',
'callback arguments' => array(
$display->did,
$node,
$node->title,
),
);
$GLOBALS['og_panels_view_tab_fix'] = check_plain($display->page_title);
}
else {
$items[] = array(
'path' => "node/{$nid}/{$display->path}",
'title' => $display->page_title,
'callback' => 'og_panels_page',
'callback arguments' => array(
$display->did,
$node,
$display->page_title,
),
'type' => MENU_LOCAL_TASK,
'access' => $display->published || og_is_node_admin($node) && user_access('manage OG panels pages'),
'weight' => $display->weight,
);
}
}
$items[] = array(
'path' => "node/{$nid}/og_panels/" . arg(3) . '/view',
'callback' => 'og_panels_page',
'callback arguments' => array(
arg(3),
$node,
),
'type' => MENU_CALLBACK,
);
if (is_numeric(arg(3))) {
$items[] = array(
'path' => "node/{$nid}/og_panels/" . arg(3) . '/panel_layout',
'callback' => 'og_panels_edit_layout',
'callback arguments' => array(
arg(3),
$node,
),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => "node/{$nid}/og_panels/" . arg(3) . '/panel_settings',
'callback' => 'og_panels_edit_layout_settings',
'callback arguments' => array(
arg(3),
$node,
),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => "node/{$nid}/og_panels/" . arg(3) . '/panel_content',
'callback' => 'og_panels_edit_content',
'callback arguments' => array(
arg(3),
$node,
),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => "node/{$nid}/og_panels/" . arg(3) . '/delete',
'title' => t('Delete'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'og_panels_delete_confirm',
arg(3),
$node,
),
'type' => MENU_CALLBACK,
);
}
}
}
}
return $items;
}
function og_panels_perm() {
return array(
'manage OG panels pages',
);
}
function og_panels_delete_confirm($did, $group_node) {
$form['did'] = array(
'#type' => 'value',
'#value' => $did,
);
$form['nid'] = array(
'#type' => 'value',
'#value' => $group_node->nid,
);
$sql = "SELECT page_title FROM {og_panels} WHERE did = %d";
$page_title = db_result(db_query($sql, $did));
$form['page_title'] = array(
'#type' => 'value',
'#value' => $page_title,
);
return confirm_form($form, t('Are you sure you want to delete %title?', array(
'%title' => $page_title,
)), isset($_GET['destination']) ? $_GET['destination'] : 'node/' . $node->nid . 'og_panels', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
}
function og_panels_delete_confirm_submit($form_id, $form_values) {
og_panels_delete($form_values['did']);
drupal_set_message(t('%title has been deleted.', array(
'%title' => $form_values['page_title'],
)));
}
function og_panels_delete($did) {
$sql = "DELETE FROM {og_panels} WHERE did = %d";
db_query($sql, $did);
panels_delete_display($did);
}
function og_panels_overview($group_node) {
drupal_set_title(check_plain($group_node->title));
$displays = og_panels_get_all($group_node->nid);
$output = drupal_get_form('og_panels_table', $displays, $group_node);
return $output;
}
function og_panels_table($displays, $group_node) {
$nid = $group_node->nid;
$form['#tree'] = TRUE;
foreach ($displays as $display) {
$item['page_title'] = array(
'#value' => l($display->page_title, "node/{$nid}/{$display->path}"),
);
$item['weight'] = array(
'#type' => 'weight',
'#default_value' => $display->weight,
);
$item['edit content'] = array(
'#value' => l(t('Edit content'), "node/{$nid}/og_panels/{$display->did}/panel_content", array(), drupal_get_destination()),
);
$item['change layout'] = array(
'#value' => l(t('Change layout'), "node/{$nid}/og_panels/{$display->did}/panel_layout"),
);
$item['edit layout settings'] = array(
'#value' => l(t('Edit layout settings'), "node/{$nid}/og_panels/{$display->did}/panel_settings"),
);
$item['edit page'] = array(
'#value' => l(t('Edit page'), "node/{$nid}/og_panels/form/{$display->did}", array(), drupal_get_destination()),
);
$item['delete page'] = array(
'#value' => l(t('Delete page'), "node/{$nid}/og_panels/{$display->did}/delete", array(), drupal_get_destination()),
);
$form['displays'][$display->did] = $item;
if ($display->default_page == 1) {
$default_page = $display->did;
}
$options[$display->did] = '';
}
$form['default_page'] = array(
'#type' => 'radios',
'#options' => $options,
'#default_value' => $default_page,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save settings'),
);
$form['group_node'] = array(
'#type' => 'value',
'#value' => $group_node,
);
return $form;
}
function theme_og_panels_table($form) {
foreach (element_children($form['displays']) as $did) {
if (is_numeric($did)) {
$rows[] = array(
drupal_render($form['default_page'][$did]),
drupal_render($form['displays'][$did]['page_title']),
drupal_render($form['displays'][$did]['weight']),
drupal_render($form['displays'][$did]['edit content']),
drupal_render($form['displays'][$did]['change layout']),
drupal_render($form['displays'][$did]['edit layout settings']),
drupal_render($form['displays'][$did]['edit page']),
drupal_render($form['displays'][$did]['delete page']),
);
}
}
$output = drupal_render($form);
$header = array(
t('Home page'),
t('Title'),
t('Weight'),
array(
'align' => 'center',
'colspan' => 5,
'data' => t('Operations'),
),
);
return theme('table', $header, $rows) . $output;
}
function og_panels_table_submit($form_id, $form_values) {
db_query("UPDATE {og_panels} SET default_page = 0 WHERE nid = %d", $form_values['group_node']->nid);
foreach ($form_values['displays'] as $did => $settings) {
$default = $did == $form_values['default_page'] ? TRUE : FALSE;
$sql = "UPDATE {og_panels} SET weight = %d, default_page = %d WHERE did = %d";
db_query($sql, $settings['weight'], $default, $did);
}
drupal_set_message(t('Updated panels configuration.'));
}
function og_panels_page($did, $group_node, $title = NULL) {
$og_panel = og_panels_get_one_by_display($did);
if ($title) {
drupal_set_title(check_plain($title));
}
$bc[] = l(t('Home'), "");
$bc[] = l(t('Groups'), "og");
if (!$og_panel->default_page) {
$bc[] = l($group_node->title, "node/{$group_node->nid}");
}
drupal_set_breadcrumb($bc);
drupal_add_feed(url("node/{$group_node->nid}/feed"), t('@name at @site', array(
'@name' => $group_node->title,
'@site' => variable_get('site_name', 'drupal'),
)));
node_tag_new($group_node->nid);
$allargs = func_get_args();
$args = array_slice($allargs, 3);
$display = og_panels_load_display($did, $group_node);
$display->args = $args;
$output = panels_render_display($display);
print theme('page', $output, $og_panel->show_blocks);
}
function og_panels_form($group_node, $did = NULL) {
drupal_set_title(check_plain($group_node->title));
if (!is_null($did)) {
$display = og_panels_get_one_by_display($did);
}
else {
$display = new stdClass();
}
$form['page_title'] = array(
'#title' => t('Page title'),
'#type' => 'textfield',
'#required' => $display->default_page ? FALSE : TRUE,
'#default_value' => $display->page_title,
'#description' => t('This is the title of the page and of the tab.'),
'#size' => 32,
);
global $base_url;
$field_prefix = "{$base_url}/node/{$group_node->nid}/";
$form[$display->default_page ? 'path_placeholder' : 'path'] = array(
'#title' => t('Path'),
'#type' => 'textfield',
'#default_value' => $display->default_page ? '' : $display->path,
'#field_prefix' => $field_prefix,
'#required' => $display->default_page ? FALSE : TRUE,
'#description' => $display->default_page ? t('This page is currently your default group home page and has no configurable path.') : '',
'#disabled' => $display->default_page,
'#size' => 32,
);
if ($display->default_page) {
$form['path'] = array(
'#type' => 'hidden',
'#value' => $display->path,
);
}
$form['show_blocks'] = array(
'#title' => t('Show blocks'),
'#type' => 'checkbox',
'#default_value' => isset($display->show_blocks) ? $display->show_blocks : TRUE,
'#description' => t('If unchecked, the standard group blocks will not be shown unless you place them into your page content. This gives admin more control over page presentation.'),
);
$form['published'] = array(
'#type' => 'checkbox',
'#title' => t('Published'),
'#default_value' => $display->published,
'#description' => t('If unchecked, this page is only accessible by group or site administrators. Thats useful while you are configuring the page.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => $did ? t('Update page') : t('Create page'),
);
$form['did'] = array(
'#type' => 'value',
'#value' => $did,
);
$form['nid'] = array(
'#type' => 'value',
'#value' => $group_node->nid,
);
return $form;
}
function og_panels_get_all($nid) {
$sql = "SELECT * FROM {og_panels} WHERE nid = %d ORDER BY default_page DESC, weight ASC";
$result = db_query($sql, $nid);
while ($row = db_fetch_object($result)) {
$rows[$row->did] = $row;
}
if (isset($rows)) {
return $rows;
}
return array();
}
function og_panels_get_one_by_display($did) {
$sql = "SELECT * FROM {og_panels} WHERE did = %d";
$result = db_query($sql, $did);
return db_fetch_object($result);
}
function og_panels_get_one_by_nid_default($nid) {
$sql = "SELECT * FROM {og_panels} WHERE nid = %d AND default_page = 1";
$result = db_query($sql, $nid);
$og_panel = db_fetch_object($result);
return is_object($og_panel) ? $og_panel : FALSE;
}
function og_panels_load_display($did, $group_node = NULL, $ct = FALSE) {
panels_load_include('plugins');
$display = panels_load_display($did);
if (is_object($group_node)) {
$display->context = array(
'og_panels' => panels_context_create('group', $group_node),
);
if ($ct) {
panels_load_include('common');
$display->content_types = panels_common_get_allowed_types('og_panels', $display->context);
}
}
return is_object($display) ? $display : FALSE;
}
function og_panels_form_validate($form_id, $form_values, $form) {
$pathblacklist = array(
'view',
'edit',
'delete',
'outline',
'load',
'render',
'clone',
);
if (in_array($form_values['path'], $pathblacklist)) {
form_error($form['path'], t('%path is a reserved system path, and cannot be used for a group page. Please enter another path.', array(
'%path' => $form_values['path'],
)));
}
else {
if (preg_match("/[^A-Za-z0-9-]/", $form_values['path'])) {
form_error($form['path'], t("Panel paths may only contain alphanumeric characters and dashes."));
}
else {
if (db_result(db_query("SELECT path FROM {og_panels} WHERE path = '%s' AND did <> %d AND nid = %d", $form_values['path'], $form_values['did'], $form_values['nid']))) {
form_error($form['path'], t("That path is currently in use by another one of your group's pages. Please enter another path."));
}
}
}
}
function og_panels_form_submit($form_id, $form_values) {
if ($form_values['did']) {
$sql = "UPDATE {og_panels} SET page_title='%s', path='%s', published=%d, show_blocks=%d WHERE did = %d";
db_query($sql, $form_values['page_title'], $form_values['path'], $form_values['published'], $form_values['show_blocks'], $form_values['did']);
drupal_set_message(t('Group page updated.'));
}
else {
$display = panels_new_display();
panels_save_display($display);
$sql = "INSERT INTO {og_panels} (did, nid, page_title, path, published, show_blocks) VALUES (%d, %d, '%s', '%s', %d, %d)";
db_query($sql, $display->did, $form_values['nid'], $form_values['page_title'], $form_values['path'], $form_values['published'], $form_values['show_blocks']);
drupal_set_message(t('Group page created.'));
return 'node/' . $form_values['nid'] . "/og_panels/{$display->did}/panel_layout";
}
}
function og_panels_set_breadcrumb($section, $group_node = NULL) {
switch ($section) {
case 'panel_edit':
$bc[] = l(t('Home'), '');
$bc[] = l($group_node->title, "node/{$group_node->nid}");
$bc[] = l(t('Pages'), "node/{$group_node->nid}/og_panels");
}
drupal_set_breadcrumb($bc);
}
function og_panels_nodeapi($node, $op) {
switch ($op) {
case 'delete':
if ($og_panels = og_panels_get_all($node->nid)) {
foreach ($og_panels as $og_panel) {
panels_delete_display($og_panel->did);
}
$sql = "DELETE FROM {og_panels} WHERE nid = %d";
db_query($sql, $node->nid);
drupal_set_message(t('Organic groups panel pages deleted.'));
}
break;
}
}
function og_panels_edit_layout($did, $group_node) {
og_panels_set_breadcrumb('panel_edit', $group_node);
$display = og_panels_load_display($did, $group_node);
return panels_edit_layout($display, t('Save'), "node/{$group_node->nid}/og_panels");
}
function og_panels_edit_layout_settings($did, $group_node) {
og_panels_set_breadcrumb('panel_edit', $group_node);
$display = og_panels_load_display($did);
return panels_edit_layout_settings($display, t('Save'), "node/{$group_node->nid}/og_panels");
}
function og_panels_edit_content($did, $group_node) {
og_panels_set_breadcrumb('panel_edit', $group_node);
$display = og_panels_load_display($did, $group_node, TRUE);
print theme('page', panels_edit($display, "node/{$group_node->nid}/og_panels", $display->content_types), FALSE);
}
function og_panels_admin_content() {
panels_load_include('common');
return drupal_get_form('panels_common_settings', 'og_panels');
}
function og_panels_panels_contexts() {
include_once './' . drupal_get_path('module', 'og_panels') . '/includes/groupcontext.inc';
$args['group'] = array(
'title' => t("Group"),
'description' => t('A node object that is flagged as an OG group type.'),
'context' => 'og_panels_context_create_group',
'settings form' => 'og_panels_context_group_settings_form',
'settings form validate' => 'og_panels_context_group_settings_form_validate',
'keyword' => 'group',
'context name' => 'group',
);
return $args;
}
function og_panels_panels_content_types() {
include_once './' . drupal_get_path('module', 'og_panels') . '/includes/groupcontent.inc';
$items['og_mission'] = array(
'title' => t('OG mission'),
'content_types' => 'og_panels_ct_list_mission',
'single' => TRUE,
'render callback' => 'og_panels_ct_render_callback_mission',
'title callback' => 'og_panels_ct_title_callback_mission',
);
$items['og_description'] = array(
'title' => t('OG description'),
'content_types' => 'og_panels_ct_list_description',
'single' => TRUE,
'render callback' => 'og_panels_ct_render_callback_description',
'title callback' => 'og_panels_ct_title_callback_description',
);
$items['og_subscribers'] = array(
'title' => t('OG members'),
'content_types' => 'og_panels_ct_list_subscribers',
'single' => TRUE,
'render callback' => 'og_panels_ct_render_callback_subscribers',
'add callback' => 'og_panels_content_types_addedit_callback_subscribers',
'edit callback' => 'og_panels_content_types_addedit_callback_subscribers',
'title callback' => 'og_panels_ct_title_callback_subscribers',
'add validate callback' => 'og_panels_content_types_validate_callback_subscribers',
'edit validate callback' => 'og_panels_content_types_validate_callback_subscribers',
);
if (module_exists('search')) {
$items['og_search'] = array(
'title' => t('Group search'),
'content_types' => 'og_panels_ct_list_search',
'single' => TRUE,
'render callback' => 'og_panels_ct_render_callback_search',
'title callback' => 'og_panels_ct_title_callback_search',
);
}
if (og_is_picture()) {
$items['og_faces'] = array(
'title' => t('OG faces'),
'content_types' => 'og_panels_ct_list_faces',
'single' => TRUE,
'render callback' => 'og_panels_ct_render_callback_faces',
'add callback' => 'og_panels_content_types_addedit_callback_faces',
'edit callback' => 'og_panels_content_types_addedit_callback_faces',
'title callback' => 'og_panels_ct_title_callback_faces',
'add validate callback' => 'og_panels_content_types_validate_callback_faces',
'edit validate callback' => 'og_panels_content_types_validate_callback_faces',
);
}
return $items;
}
function og_panels_panels_relationships() {
include_once './' . drupal_get_path('module', 'og_panels') . '/includes/grouprelationships.inc';
$args['group_from_node'] = array(
'title' => t("Group from node"),
'keyword' => 'group',
'description' => t('Adds a group from a node context; if multiple groups are associated with a node, this will get the "first" group only.'),
'required context' => new panels_required_context(t('Node'), 'node'),
'context' => 'panels_group_from_node_context',
);
return $args;
}
function og_panels_block_info($module, $delta, &$info) {
switch ($delta) {
case 2:
unset($info);
break;
case 'default':
$info['icon'] = 'user-multiple.png';
$info['required context'] = new panels_required_context(t('Group'), 'group');
$info['path'] = drupal_get_path('module', 'og_panels') . '/';
$info['category'] = t('Organic groups');
break;
}
if ($delta == 3 || $delta == 6) {
unset($info['required context']);
}
}