Index: og_panels.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/og/og_panels.module,v retrieving revision 1.39 diff -u -r1.39 og_panels.module --- og_panels.module 11 Sep 2008 14:04:34 -0000 1.39 +++ og_panels.module 8 Oct 2008 19:51:12 -0000 @@ -1,138 +1,152 @@ 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'))) .'
'; + 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'))) .'
'; } } -function og_panels_menu($may_cache) { - if ($may_cache) { - $items[] = array( - 'path' => 'admin/og/og_panels', - 'title' => 'Organic groups panels', - 'description' => 'Configure the content that is available to group admins when creating group pages.', - 'callback' => 'og_panels_admin_content', - 'access' => user_access('administer organic groups'), - ); +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 callback' => 'user_access', + 'access arguments' => array('administer organic groups'), + ); + $items['node/%node/og_panels'] = array( + 'title' => t('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' => t('List'), + 'access callback' => 'og_panels_access_admin', + 'access arguments' => array(1), + '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' => arg(4) ? t('Edit page') : t('Add new page'), + 'access callback' => 'og_panels_access_admin', + 'access arguments' => array(1), + 'type' => MENU_LOCAL_TASK, + 'weight' => 0, + ); + $items['node/%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, + ); + + $items['node/%node/og_panels/%/panel_settings'] = array( + 'page callback' => 'og_panels_edit_layout_settings', + 'page arguments' => array(3, 1), + 'type' => MENU_CALLBACK, + ); + + $items['node/%node/og_panels/%/panel_content'] = array( + 'page callback' => 'og_panels_edit_content', + 'page arguments' => array(3, 1), + 'type' => MENU_CALLBACK, + ); + + $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, + ); + return $items; +} + +/** + * Implementation of hook_menu_alter() + * + * This replaces old "hijack" functionlaity for node/view on og_panel nodes + */ +function og_panels_menu_alter(&$callbacks) { + $callbacks['node/%node'] = array( + 'title callback' => 'node_page_title', + 'title arguments' => array(1), + 'page callback' => 'og_panels_node_page_view', + 'page arguments' => array(1), + 'access callback' => 'node_access', + 'access arguments' => array('view', 1), + 'type' => MENU_CALLBACK, + ); + $callbacks['node/%node/view'] = array( + 'title callback' => 'og_panels_main_tab_title', + 'title arguments' => array(1), + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => -10, + ); +} + +/** + * Override default node_page functionality if we're in an og_panels situation + */ +function og_panels_node_page_view($node, $path = NULL) { + $displays = og_panels_get_all($node->nid); + foreach ($displays as $display) { + // match a default display and a plain node url + if (($display->default_page && $display->published && $path == NULL) || $display->path == $path) { + return og_panels_page($display->did, $node, $node->title); + } } - 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' => 'Pages', - 'callback' => 'og_panels_overview', - 'callback arguments' => array($node), - 'access' => og_is_group_admin($node) && user_access('manage OG panels pages'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 8, - ); - - $items[] = array( - 'path' => "node/$nid/og_panels/list", - 'title' => '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) ? 'Edit page' : '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') { - // Hijack the menu handler for this node. - $items[] = array( - 'path' => "node/$nid", - 'title' => $node->title, // doesn't work - 'callback' => 'og_panels_page', - 'callback arguments' => array($display->did, $node, $node->title), - ); - - /* - * Optional. Horrible hack since the tab title is not changeable in D5. Add the following code - * to your theme's template.php in the _phptemplate_variables('page') section. - * if (isset($GLOBALS['og_panels_view_tab_fix'])) { - * $variables['tabs'] = str_replace('>View<', '>'. $GLOBALS['og_panels_view_tab_fix']. '<', $variables['tabs']); - * } - */ - $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', - // have to pass all these args so the args are known in panels_page() - 'callback arguments' => array($display->did, $node, $display->page_title), - 'type' => MENU_LOCAL_TASK, - 'access' => $display->published || (og_is_group_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' => 'Delete', - 'callback' => 'drupal_get_form', - 'callback arguments' => array('og_panels_delete_confirm', arg(3), $node), - 'type' => MENU_CALLBACK, - ); - } - } + return node_page_view($node); +} + +/** + * 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 $items; + return t('View'); } function og_panels_perm() { return array('manage OG panels pages'); } -function og_panels_delete_confirm($did, $group_node) { +/** + * 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"; @@ -175,9 +189,11 @@ * * @return $form array **/ -function og_panels_table($displays, $group_node) { +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) { $item['page_title'] = array('#value' => l($display->page_title, "node/$nid/$display->path")); $item['weight'] = array('#type' => 'weight', '#default_value' => $display->weight); @@ -206,12 +222,25 @@ '#type' => 'submit', '#value' => t('Save settings'), ); - + $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 @@ -239,10 +268,10 @@ 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; +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'] ? TRUE : FALSE; $sql = "UPDATE {og_panels} SET weight = %d, default_page = %d WHERE did = %d"; db_query($sql, $settings['weight'], $default, $did); } @@ -286,7 +315,7 @@ * * @return void **/ -function og_panels_form($group_node, $did = NULL) { +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); @@ -405,6 +434,7 @@ */ 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)); @@ -416,15 +446,15 @@ return is_object($display) ? $display : FALSE; } -function og_panels_form_validate($form_id, $form_values, $form) { +function og_panels_form_validate($form, &$form_state) { $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']))); + 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_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_values['path'], $form_values['did'], $form_values['nid']))) { + 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.")); } } @@ -434,10 +464,10 @@ * * @return void **/ -function og_panels_form_submit($form_id, $form_values) { - if ($form_values['did']) { +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_values['page_title'], $form_values['path'], $form_values['published'], $form_values['show_blocks'], $form_values['did']); + 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']); drupal_set_message(t('Group page updated.')); } else { @@ -445,9 +475,9 @@ $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']); + 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']); drupal_set_message(t('Group page created.')); - return 'node/'. $form_values['nid']. "/og_panels/$display->did/panel_layout"; + $form_state['redirect'] = 'node/'. $form_state['values']['nid']. "/og_panels/$display->did/panel_layout"; } }