0){ $group_node = node_load(arg(1)); if (og_is_group_type($group_node->type)) { og_set_theme($group_node); og_set_group_context($group_node); og_set_language($group_node); if( (arg(2) == "" || arg(2) == 'view') && variable_get('page_manager_node_view_disabled',0) == 1){ drupal_set_message(t("In order to view the homepage, you need to enable node_view template, click ").'"destination=node/$group_node->nid")).'">'.t("here").' '.t("to enable."),"error"); } } } } function og_panels_help($path, $arg) { switch ($path) { 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 og_panels settings page. You might want to make some Views available using admin/panels/views. 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 '
'. 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 group home page. That page will then display when visitors first arrive at your group.') .'
'. t('Start by clicking the Add new page tab. Then you will choose a custom layout for your page. Then you will want to edit content for your custom page.', array('!url' => url('node/'. arg(1). '/og_panels/form'))) .'
'; } } /** * Implementation of hook_menu */ function og_panels_menu() { $items['admin/og/og_panels'] = array( 'title' => 'Organic groups panels', 'description' => 'Configure the content that is available to group admins when creating group pages.', 'page callback' => 'og_panels_admin_content', 'access arguments' => array('administer organic groups'), ); $items['node/%node/og_panels'] = array( 'title' => 'Pages', 'page callback' => 'og_panels_overview', 'page arguments' => array(1), 'access callback' => 'og_panels_access_admin', 'access arguments' => array(1), 'type' => MENU_LOCAL_TASK, 'weight' => 8, ); $items['node/%node/og_panels/list'] = array( 'title' => 'List', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items['node/%node/og_panels/form'] = array( 'page callback' => 'drupal_get_form', 'page arguments' => array('og_panels_form', 1), 'title callback' => 'og_panels_tab_edit_title', 'title arguments' => array(4), 'access callback' => 'og_panels_access_admin', 'access arguments' => array(1), 'type' => MENU_LOCAL_TASK, 'weight' => 0, ); $items['node/%/og_panels/%/view'] = array( 'page callback' => 'og_panels_page', 'page arguments' => array(3, 1), 'type' => MENU_CALLBACK, ); $items['node/%node/og_panels/%/panel_layout'] = array( 'page callback' => 'og_panels_edit_layout', 'page arguments' => array(3, 1), 'type' => MENU_CALLBACK, 'access callback' => 'og_panels_access_admin', 'access arguments' => array(1), ); $items['node/%node/og_panels/%/panel_settings'] = array( 'page callback' => 'og_panels_edit_layout_settings', 'page arguments' => array(3, 1), 'type' => MENU_CALLBACK, 'access callback' => 'og_panels_access_admin', 'access arguments' => array(1), ); $items['node/%node/og_panels/%/panel_content'] = array( 'page callback' => 'og_panels_edit_content', 'page arguments' => array(3, 1), 'type' => MENU_CALLBACK, 'access callback' => 'og_panels_access_admin', 'access arguments' => array(1), ); $items['node/%node/og_panels/%/delete'] = array( 'title' => 'Delete', 'page callback' => 'drupal_get_form', 'page arguments' => array('og_panels_delete_confirm', 3, 1), 'type' => MENU_CALLBACK, 'access callback' => 'og_panels_access_admin', 'access arguments' => array(1), ); // Add generic realm of callbacks for og_panels tabs. $items = array_merge($items, _og_panels_nodes_menu()); return $items; } /** * Implementation of hook_menu_alter() * * Allow the overriding of the default node/%node/view tab! * * We can use 1 as the argument here, as a pane set to be the homepage always gets tab_num #1 */ function og_panels_menu_alter(&$items) { $items['node/%node/view'] = array( 'title callback' => 'og_panels_tab_title', 'title arguments' => array(1, NULL, TRUE), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10 ); } /** * Implementation of hook_ctools_plugin_api() * * Needed so that our other hooks are picked up. */ function og_panels_ctools_plugin_api($module, $api) { if ($module == 'page_manager' && $api == 'pages_default') { return array('version' => 1); } } /** * Implementation of hook_ctools_plugin_dierctory() to let the system know * we implement task_handler, content_type and context plugins. */ function og_panels_ctools_plugin_directory($module, $plugin) { if ($module == 'page_manager' || $module == 'ctools') { return 'plugins/' . $plugin; } } /** * Implementation of hook_default_page_manager_handlers() */ function og_panels_default_page_manager_handlers() { $handler = new stdClass; $handler->disabled = FALSE; /* Edit this to true to make a default handler disabled initially */ $handler->api_version = 1; $handler->name = 'node_view_og_panel'; $handler->task = 'node_view'; $handler->subtask = ''; $handler->handler = 'og_panel'; $handler->weight = -99; $handler->conf = array( 'autogenerate_title' => FALSE, 'title' => 'OG Panels', 'contexts' => array(), 'relationships' => array( '0' => array( 'context' => 'argument_nid_1', 'name' => 'og', 'id' => 1, 'identifier' => 'Organic Group from node', 'keyword' => 'og', ), ), ); $handlers[$handler->name] = $handler; return $handlers; } function og_panels_tab_edit_title($item = NULL) { if ($item) { return t('Edit page'); } else { return t('Add new page'); } } /** * Custom callback to return a limited array of menu callbacks allowing lots of og_panels, * but with only a few menu router items. * * Based on: http://drupal.org/node/362031 * */ function _og_panels_nodes_menu() { $items = array(); $result = db_query("SELECT DISTINCT tab_num FROM {og_panels} ORDER BY tab_num ASC"); while ($tab = db_fetch_object($result)) { $items['node/%/og-panel/'. $tab->tab_num] = array( 'title callback' => 'og_panels_tab_title', 'title arguments' => array(1, $tab->tab_num), 'page callback' => 'og_panels_page', 'page arguments' => array(1, $tab->tab_num), 'access callback' => '_og_panels_node_access', 'access arguments' => array(1, $tab->tab_num), 'type' => MENU_LOCAL_TASK, 'tab_parent' => 'node/%', 'tab_root' => 'node/%', ); } return $items; } /** * Title callback for tab menu items * * This takes input from both the menu tabs, and a home page override. * * It also sets the page title back to being the node name, and sets the tab to "home" in the event of no homepage override. */ function og_panels_tab_title($node, $tab_num = 1, $view = FALSE) { if (!is_object($node)) { $node = node_load($node); } if (!og_is_group_type($node->type)) { return t('View'); } $tab = og_panels_node_data($node->nid, $tab_num); if ($view && empty($tab['default_page'])) { return t('Home'); } else { // does this really do what is intented? code seems strange. drupal_set_title($node->title); return $tab['page_title']; } } /** * Helper function to load og_panels tab info for a node * * @param int $nid * The node id we are interested in. * @param int $tab_num * Optional: the specific tab number. * @returns * Returns an array of og_panels row-arrays, or just one array for a tab_num, if specified. */ function og_panels_node_data($nid, $tab_num = FALSE) { static $data = array(); if (!isset($data[$nid])) { $result = db_query("SELECT * FROM {og_panels} WHERE nid = %d", $nid); while ($tab = db_fetch_array($result)) { $data[$nid][$tab['tab_num']] = $tab; } } if (isset($data[$nid][$tab_num])) { return isset($data[$nid][$tab_num]) ? $data[$nid][$tab_num] : array(); } return isset($data[$nid]) ? $data[$nid] : array(); } /** * Access callback. * * Find out if a panel exists for this node and use node_access if so. * * Otherwise, no such panel, so FALSE. */ function _og_panels_node_access($nid, $tab_num) { $tab = og_panels_node_data($nid, $tab_num); if (isset($tab['nid'])) { if (!empty($tab['default_page'])) { // A bit counter-intuitive. // This prevents duplicate tabs from showing up when we override the "view" title. // Because we get that panel through our page_manager task_handler, and not a direct // menu callback. return FALSE; } $node = node_load($nid); if ($tab['published']) { return node_access('view', $node); } } else { return FALSE; } } function _og_panels_node_page_title($nid) { return node_page_title(node_load($nid)); } /** * Override default "view" tab if we're in a og_panels situation */ function og_panels_main_tab_title($node) { $displays = og_panels_get_all($node->nid); foreach ($displays as $display) { if ($display->default_page) { return check_plain($display->page_title); } } return t('View'); } /** * Implementation of hook_perm * * Add import and export OG panels pages permission */ function og_panels_perm() { return array('manage OG panels pages','import and export OG panels pages'); } /** * Manu access functions for checking multiple variables */ function og_panels_access_admin($node) { if (og_is_group_admin($node) && user_access('manage OG panels pages')) { return TRUE; } } function og_panels_access_view($node, $display) { // show admins unpublished displays if ($display->published || (og_is_group_admin($node) && user_access('manage OG panels pages'))) { return TRUE; } } function og_panels_delete_confirm(&$form_state, $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['values']['did'], $form_values['values']['nid']); drupal_set_message(t('%title has been deleted', array('%title' => $form_values['values']['page_title']))); } /** * Remove the og_panel link and the panel itself. * * Rebuild menu so sub-task dissapears right away. */ function og_panels_delete($did, $nid) { if (module_exists('path')) { // release path alias // need tab_num here for the path alias $tab_num = db_result(db_query("SELECT tab_num FROM {og_panels} WHERE nid = %d AND did = %d", $nid, $did)); path_set_alias('node/'. $nid .'/og-panel/'. $tab_num); } $sql = "DELETE FROM {og_panels} WHERE did = %d"; db_query($sql, $did); panels_delete_display($did); _og_panels_tab_renumber($nid); } /** * Menu callback. List the pages for this specified group. Provide helpful operations links. * * @return string **/ 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; } /** * A form for setting the group homepage. Includes a helpful table of Pages and their operations links. * * @return $form array **/ function og_panels_table(&$form_state, $displays, $group_node) { $nid = $group_node->nid; $form['#tree'] = TRUE; // #tree must be true in order to separate out the entries in the weight field $options = array(); $default_page = NULL; foreach ($displays as $display) { if ($display->default_page == 1) { //for the default page, make sure it's linking to the node/$nid directly $item['page_title'] = array('#value' => l($display->page_title, "node/$nid")); } else { $item['page_title'] = array('#value' => l($display->page_title, "node/$nid/og-panel/$display->tab_num")); } $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('query' => drupal_get_destination()))); $item['change layout'] = array('#value' => l(t('Change layout'), "node/$nid/og_panels/$display->did/panel_layout")); $item['edit page'] = array('#value' => l(t('Edit page'), "node/$nid/og_panels/form/$display->did", array('query' => drupal_get_destination()))); $item['delete page'] = array('#value' => l(t('Delete page'), "node/$nid/og_panels/$display->did/delete", array('query' => drupal_get_destination()))); $form['displays'][$display->did] = $item; // Store the default_page for later. if ($display->default_page == 1) { $default_page = $display->did; } // Prepare the options for the radios. $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['reset'] = array( '#type' => 'submit', '#value' => t('Reset Homepage'), ); $form['group_node'] = array('#type' => 'value', '#value' => $group_node); return $form; } /** * Implementation of hook_theme() * * For the table theme on the form */ function og_panels_theme($existing, $type, $theme, $path) { return array( 'og_panels_table' => array( 'arguments' => array('form' => NULL), ), ); } /** * Wrangle the $form into a tabular listing of pages. * * @ingroup Themeable functions * * @return void **/ function theme_og_panels_table($form) { drupal_add_tabledrag('og-panels-table-table', 'order', 'sibiling', 'weightorder'); foreach (element_children($form['displays']) as $did) { if (is_numeric($did)) { $form['displays'][$did]['weight']['#attributes']['class'] = 'weightorder'; $rows[] = array( 'class' => 'draggable', 'data' => 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 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' => 4, 'data' => t('Operations'))); return theme('table', $header, $rows, array('id' => 'og-panels-table-table')). $output; } function og_panels_table_submit($form, &$form_state) { db_query("UPDATE {og_panels} SET default_page = 0 WHERE nid = %d", $form_state['values']['group_node']->nid); foreach ($form_state['values']['displays'] as $did => $settings) { $default = ($did == $form_state['values']['default_page'] && $form_state['values']['op'] != $form_state['values']['reset']) ? TRUE : FALSE; $sql = "UPDATE {og_panels} SET weight = %d, default_page = %d WHERE did = %d"; db_query($sql, $settings['weight'], $default, $did); } // compact the tab_nums and rebuild menus _og_panels_tab_renumber($form_state['values']['group_node']->nid); drupal_set_message(t('Updated panels configuration.')); } /** * A menu callback. Renders an og_panel based upon the nid and current path (if any). * * @param int $nid * Node id of the group * * @param int $tab_num * Number for the tab * * @param bool $print * If this is being called from within the page_manager, return rather than print. * * @return void **/ function og_panels_page($nid, $tab_num, $print = TRUE) { $tab = og_panels_node_data($nid, $tab_num); $group_node = node_load($tab['nid']); // Set breadcrumb and title on non group nodes if ($tab['page_title']) { drupal_set_title(check_plain($tab['page_title'])); } // Mark node as read and show feed icon for any group panel page (how to do this better?) 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($tab['did'], $group_node); $display->args = $args; $output = panels_render_display($display); if ($print) { print theme('page', $output, $tab['show_blocks']); } else { return $output; } } /** * Add/edit an og_panel. * * @return void **/ function og_panels_form(&$form_state, $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, ); $form[$display->default_page ? 'path_placeholder' : 'path'] = array( '#title' => t('Path'), '#type' => 'textfield', '#default_value' => $display->default_page ? '' : $display->path, '#field_prefix' => url('node/'. $group_node->nid, array('absolute' => TRUE)) .'/', '#description' => $display->default_page ? t('This page is currently your default group home page and has no configurable path.') : t('An optional path alias for this page.'), '#disabled' => $display->default_page, '#size' => 32, '#access' => module_exists('path'), ); 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->did) ? $display->published : TRUE, '#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); $form['tab_num'] = array('#type' => 'value', '#value' => $display->tab_num); return $form; } /** * Return an array of all og_panels attached to the given nid. * * @param int $nid * @return array $rows * An associative array keyed by the $did of the og_panel */ function og_panels_get_all($nid) { $sql = "SELECT * FROM {og_panels} WHERE nid = %d ORDER BY default_page DESC, weight ASC, page_title ASC"; $result = db_query($sql, $nid); while ($row = db_fetch_object($result)) { $rows[$row->did] = $row; } if (isset($rows)) { return $rows; } return array(); } /** * Load an og_panels object. * * @param int $did * @return object $og_panel */ 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); } /** * Load the default og_panels object, if any, for the given nid. * * @param int $nid * @return mixed $og_panel * Either returns the og_panel object, or FALSE if no default panel was found for the nid */ 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; } /** * Load an og_panel's display information. * * Loads a panels display object with various parameters, depending on the information passed into the load function. * * @param int $did * The did of the panels display. * @param object $group_node = NULL * The node object for the group to which the panel is attached. * @param bool $ct = FALSE * If TRUE, content_types are also loaded into the $display object * * @return mixed * Either returns a display object, or FALSE if no display was found with the parameters provided. */ function og_panels_load_display($did, $group_node = NULL, $ct = FALSE) { panels_load_include('plugins'); ctools_include('context'); $display = panels_load_display($did); if (is_object($group_node)) { // Hard-coding context identifiers for now. This needs a permanent fix. $nc = ctools_context_create('node', $group_node); $nc->identifier = 'Node'; $nc->keyword = 'node'; $gc = ctools_context_create('og', $group_node); $gc->identifier = 'Group'; $gc->keyword = 'og'; $display->context = array( 'argument_nid_1' => $nc, 'relationship_og_1' => $gc, ); 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, &$form_state) { $pathblacklist = array('view', 'edit', 'delete', 'outline', 'load', 'render', 'clone'); if (in_array($form_state['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_state['values']['path']))); } else if (preg_match("/[^A-Za-z0-9-]/", $form_state['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_state['values']['path'], $form_state['values']['did'], $form_state['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.")); } } /** * INSERT or UPDATE a new og_panel. If insert, just default to two column * stacked layout for now. @TODO: let user select layout during page creation. * * Handles tab numbering and path aliases. * * @return void **/ function og_panels_form_submit($form, &$form_state) { if ($form_state['values']['did']) { $sql = "UPDATE {og_panels} SET page_title = '%s', path = '%s', published = %d, show_blocks = %d WHERE did = %d"; db_query($sql, $form_state['values']['page_title'], $form_state['values']['path'], $form_state['values']['published'], $form_state['values']['show_blocks'], $form_state['values']['did']); if ($form_state['values']['path'] != '' && module_exists('path')) { _og_panels_tab_path_alias($form_state['values']['nid'], $form_state['values']['tab_num'], $form_state['values']['path']); } drupal_set_message(t('Group page updated.')); } else { // Create a new display and record that. $display = panels_new_display(); // TODO: let user select layout during creation. $display->layout = 'twocol_stacked'; panels_save_display($display); $form_state['values']['tab_num'] = _og_panels_tab_num($form_state['values']['nid']); $sql = "INSERT INTO {og_panels} (did, nid, page_title, path, published, show_blocks, tab_num) VALUES (%d, %d, '%s', '%s', %d, %d, %d)"; db_query($sql, $display->did, $form_state['values']['nid'], $form_state['values']['page_title'], $form_state['values']['path'], $form_state['values']['published'], $form_state['values']['show_blocks'], $form_state['values']['tab_num']); _og_panels_tab_renumber($form_state['values']['nid']); drupal_set_message(t('Group page created.')); $form_state['redirect'] = 'node/'. $form_state['values']['nid']. '/og_panels'; } } /** * Helper function to make path aliases for tab_nums, since we renumber them often */ function _og_panels_tab_path_alias($nid, $tab_num, $path) { $alias = drupal_get_path_alias('node/'. $nid) .'/'. $path; path_set_alias('node/'. $nid. '/og-panel/'. $tab_num, $alias); } /** * Get next tab number for node. * * Rebuild menu if new number > current max. */ function _og_panels_tab_num($nid) { $max = db_result(db_query("SELECT MAX(tab_num) FROM {og_panels}", $nid)); $tab_num = db_result(db_query("SELECT MAX(tab_num) + 1 FROM {og_panels} WHERE nid = %d", $nid)); if ($tab_num > $max || $max == 0) { // A new high number! We want to rebuild at the end of the page cycle, not right now. variable_set('menu_rebuild_needed', TRUE); } // if this is the first tab, it's going to be NULL if ($tab_num == NULL) { $tab_num = 1; } return $tab_num; } /** * Internal function to compact/renumber tabs based on weight */ function _og_panels_tab_renumber($nid) { $displays = array(); $result = db_query("SELECT * FROM {og_panels} WHERE nid = %d ORDER BY default_page DESC, weight ASC, page_title ASC", $nid); while($display = db_fetch_object($result)) { $displays[] = $display; } // Now, clear them all! db_query("DELETE FROM {og_panels} WHERE nid = %d", $nid); if (module_exists('path')) { db_query("DELETE FROM {url_alias} WHERE src LIKE 'node/%d/og-panel/%%'", $nid); } // Rewrite with newly indexed tab_nums, starting at 1. $tab_num = 1; foreach($displays as $object) { $original_tab_num = $object->tab_num; $object->tab_num = $tab_num; // remap paths if this tab has one. if ($object->path != '' && module_exists('path')) { // set new alias. _og_panels_tab_path_alias($object->nid, $object->tab_num, $object->path); } drupal_write_record('og_panels', $object); $tab_num++; } } 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); } /** * Implementations of hook_nodeapi * * On node load, make sure non-Home page panel pages have their title set correctly */ function og_panels_nodeapi($node, $op) { switch ($op) { case 'load': if(og_is_group_type($node->type) && $node->nid == arg(1)){ if(arg(2) == 'og-panel'){ $did = (int)arg(3); if($did > 0){ $result = db_query("SELECT page_title FROM {og_panels} WHERE nid = %d AND published = 1 AND default_page = 0 AND tab_num = %d", $node->nid, $did); $row = db_fetch_object($result); if(is_object($row)){ $node->title = $row->page_title; } } } else{ $result = db_query("SELECT page_title FROM {og_panels} WHERE nid = %d AND published = 1 AND default_page = 1", $node->nid); $row = db_fetch_object($result); if(is_object($row)){ $node->title = $row->page_title; } } } break; case 'delete': if ($og_panels = og_panels_get_all($node->nid)) { foreach ($og_panels as $og_panel) { og_panels_delete($og_panel->did, $node->nid); //make sure when deleting a group, the url alias are deleted as well } $sql = "DELETE FROM {og_panels} WHERE nid = %d"; db_query($sql, $node->nid); drupal_set_message(t('Organic groups panel pages deleted.')); } break; } } // --------------------------------------------------------------------------- // Meat of the Panels API; almost completely passing through to panels.module /** * Pass through to the panels layout editor. * * @param int $did * the $did of the og_panel to be edited. * * @param object $group_node * the node object to which the og_panel is attached. */ function og_panels_edit_layout($did, $group_node) { og_panels_set_breadcrumb('panel_edit', $group_node); $display = og_panels_load_display($did, $group_node); // TODO I don't believe that having the context present is necessary for editing the layout. return panels_edit_layout($display, t('Save'), "node/$group_node->nid/og_panels",'og_panels'); } /** * Pass through to the panels content editor. * * @param int $did * the $did of the og_panel to be edited. * * @param object $group_node * the node object to which the og_panel is attached. */ 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 this with theme('page') so that blocks are disabled while editing a display. // This is important because negative margins in common block layouts (i.e, Garland) // messes up the drag & drop. 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'); } /** * Implementation of hook_form_alter * * attach og_panels_export_import_form before the panel edit form * * When views_exposed_form is presented, modify its form action so that the filtering behavior work * as expected while not destroying the OG panel tabs */ function og_panels_form_alter(&$form, $form_state, $form_id){ if($form_id == 'panels_edit_display_form' && arg(0) == 'node' && arg(1) > 0 && arg(2) == 'og_panels' && arg(3) > 0){ if(user_access('import and export OG panels pages')){ $did = (int)arg(3); $form['#prefix'] = drupal_get_form('og_panels_export_import_form', $did); } } else if($form_id == 'views_exposed_form'){ if(arg(0) == 'node' && arg(1) > 0){ $group_node = node_load((int)arg(1)); if(og_is_group_type($group_node->type)){ $form['#action'] = url($_GET['q']); } } } } /** * build the og panels export import form */ function og_panels_export_import_form(){ $form = array(); //add extra condition check if( arg(0) == 'node' && arg(1) > 0 && arg(2) == 'og_panels' && arg(3) > 0 ){ $args = func_get_args(); $display_id = (int)$args[1]; $display = og_panels_load_display($display_id); $panel_code = panels_export_display($display); $form['view'] = array( '#type' => 'fieldset', '#title' => t('Export'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['view']['exported'] = array( '#type' => 'textarea', '#value' => $panel_code, ); $form['import'] = array( '#type' => 'fieldset', '#title' => t('Import From Code'), '#weight' => 5, '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['import']['display_id'] = array( '#type' => 'hidden', '#value' => $display_id, ); $form['import']['code'] = array( '#type' => 'textarea', '#title' => t('Import From Code'), ); $form['import']['submit'] = array( '#type' => 'submit', '#value' => t("Import"), ); } return $form; } function og_panels_export_import_form_submit(&$form, $form_state){ //og_panels_import_from_code og_panels_import_from_code($form_state['values']['code'], $form_state['values']['display_id']); } /** * Import a piece of code and save as a panel display * * @param string $code * the exported code representing a OG panel page * * @param int $display_id * the exported OG panel page's display id */ function og_panels_import_from_code($code, $display_id){ if(strlen($code) > 0 && $display_id > 0){ ob_start(); eval($code); ob_end_clean(); if(is_object($display)){ $old_did = $display_id; //tricky, we need to update the display's layout, layout_settings, panel_settings, cache, title, hide_title, title_pane db_query("UPDATE {panels_display} SET layout = '%s', layout_settings = '%s', panel_settings = '%s', cache = '%s', title = '%s', hide_title = '%d', title_pane = '%d' WHERE did = '%d'", $display->layout, serialize($display->layout_settings), serialize($display->panel_settings), serialize($display->cache), $display->title, $display->hide_title, $display->title_pane, $old_did); $display = panels_save_display($display); $new_did = $display->did; //tricky, we need to delete the old display's panels pane info and update it with the new info db_query("DELETE FROM {panels_pane} WHERE did = '%d'", $old_did); db_query("UPDATE {panels_pane} SET did = '%d' WHERE did = '%d'", $old_did, $new_did); } } }