Newer
Older
Moshe Weitzman
committed
<?php
// $Id$
function og_panels_help($path, $arg) {
switch ($path) {
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')));
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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() {
$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 and task_handler plugins.
*/
function og_panels_ctools_plugin_directory($module, $plugin) {
if ($module == 'page_manager') {
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',
);
$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');
Moshe Weitzman
committed
}
}
/**
* 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/%',
Moshe Weitzman
committed
);
Moshe Weitzman
committed
}
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
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);
}
$tab = og_panels_node_data($node->nid, $tab_num);
if ($view && !$tab['default_page']) {
return t('Home');
}
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 (!$data[$nid]) {
$result = $result = db_query("SELECT * FROM {og_panels} WHERE nid = %d", $nid);
while ($tab = db_fetch_array($result)) {
$data[$nid][$tab['tab_num']] = $tab;
}
}
if ($tab_num) {
return $data[$nid][$tab_num];
}
elseif (og_panels_node_data) {
return $data[$nid];
}
Moshe Weitzman
committed
else {
return 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 ($tab['nid']) {
if ($tab['default_page']) {
Moshe Weitzman
committed
// 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;
}
Moshe Weitzman
committed
$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');
Moshe Weitzman
committed
}
Moshe Weitzman
committed
function og_panels_perm() {
return array('manage 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) {
Moshe Weitzman
committed
$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);
Moshe Weitzman
committed
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'])));
Moshe Weitzman
committed
}
/**
* 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);
}
Moshe Weitzman
committed
$sql = "DELETE FROM {og_panels} WHERE did = %d";
db_query($sql, $did);
panels_delete_display($did);
_og_panels_tab_renumber($nid);
Moshe Weitzman
committed
}
Moshe Weitzman
committed
/**
* Menu callback. List the pages for this specified group. Provide helpful operations links.
Moshe Weitzman
committed
* @return string
**/
Moshe Weitzman
committed
function og_panels_overview($group_node) {
Moshe Weitzman
committed
$displays = og_panels_get_all($group_node->nid);
$output = drupal_get_form('og_panels_table', $displays, $group_node);
return $output;
}
Moshe Weitzman
committed
/**
* A form for setting the group homepage. Includes a helpful table of Pages and their operations links.
Moshe Weitzman
committed
* @return $form array
**/
function og_panels_table(&$form_state, $displays, $group_node) {
Moshe Weitzman
committed
$nid = $group_node->nid;
Moshe Weitzman
committed
$form['#tree'] = TRUE; // #tree must be true in order to separate out the entries in the weight field
$options = array();
$default_page = NULL;
Moshe Weitzman
committed
foreach ($displays as $display) {
$item['page_title'] = array('#value' => l($display->page_title, "node/$nid/og-panel/$display->tab_num"));
Moshe Weitzman
committed
$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())));
Moshe Weitzman
committed
$form['displays'][$display->did] = $item;
Moshe Weitzman
committed
// Store the default_page for later.
if ($display->default_page == 1) {
$default_page = $display->did;
}
// Prepare the options for the radios.
$options[$display->did] = '';
Moshe Weitzman
committed
}
Moshe Weitzman
committed
$form['default_page'] = array(
'#type' => 'radios',
'#options' => $options,
Moshe Weitzman
committed
'#default_value' => $default_page,
);
Moshe Weitzman
committed
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save settings'),
Moshe Weitzman
committed
);
$form['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset Homepage'),
);
Moshe Weitzman
committed
Moshe Weitzman
committed
$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),
),
);
}
Moshe Weitzman
committed
/**
* Wrangle the $form into a tabular listing of pages.
*
* @ingroup Themeable functions
Moshe Weitzman
committed
* @return void
**/
Moshe Weitzman
committed
function theme_og_panels_table($form) {
drupal_add_tabledrag('og-panels-table-table', 'order', 'sibiling', 'weightorder');
Moshe Weitzman
committed
foreach (element_children($form['displays']) as $did) {
Moshe Weitzman
committed
if (is_numeric($did)) {
$form['displays'][$did]['weight']['#attributes']['class'] = 'weightorder';
Moshe Weitzman
committed
$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']),
),
Moshe Weitzman
committed
);
}
}
Moshe Weitzman
committed
$output = drupal_render($form);
Moshe Weitzman
committed
$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;
Moshe Weitzman
committed
}
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;
Moshe Weitzman
committed
$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);
Moshe Weitzman
committed
drupal_set_message(t('Updated panels configuration.'));
Moshe Weitzman
committed
}
Moshe Weitzman
committed
/**
* 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.
*
Moshe Weitzman
committed
* @return void
**/
Moshe Weitzman
committed
function og_panels_page($nid, $tab_num, $print = TRUE) {
$tab = og_panels_node_data($nid, $tab_num);
Moshe Weitzman
committed
$group_node = node_load($tab['nid']);
og_set_group_context($group_node);
// Set breadcrumb and title on non group nodes
if ($tab['page_title']) {
drupal_set_title(check_plain($tab['page_title']));
Moshe Weitzman
committed
// 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;
Moshe Weitzman
committed
$output = panels_render_display($display);
if ($print) {
print theme('page', $output, $tab['show_blocks']);
}
else {
return $output;
}
Moshe Weitzman
committed
}
Moshe Weitzman
committed
/**
* Add/edit an og_panel.
Moshe Weitzman
committed
* @return void
**/
function og_panels_form(&$form_state, $group_node, $did = NULL) {
Moshe Weitzman
committed
if (!is_null($did)) {
$display = og_panels_get_one_by_display($did);
}
else {
$display = new stdClass;
}
Moshe Weitzman
committed
$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,
);
Moshe Weitzman
committed
$form[$display->default_page ? 'path_placeholder' : 'path'] = array(
Moshe Weitzman
committed
'#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.'),
Moshe Weitzman
committed
'#disabled' => $display->default_page,
'#size' => 32,
'#access' => module_exists('path'),
Moshe Weitzman
committed
);
Moshe Weitzman
committed
if ($display->default_page) {
$form['path'] = array(
'#type' => 'hidden',
'#value' => $display->path,
);
}
Moshe Weitzman
committed
$form['show_blocks'] = array(
'#title' => t('Show blocks'),
'#type' => 'checkbox',
'#default_value' => isset($display->show_blocks) ? $display->show_blocks : TRUE,
Moshe Weitzman
committed
'#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.'),
Moshe Weitzman
committed
);
Moshe Weitzman
committed
$form['published'] = array(
'#type' => 'checkbox',
'#title' => t('Published'),
'#default_value' => ($display->did) ? $display->published : TRUE,
Moshe Weitzman
committed
'#description' => t('If unchecked, this page is only accessible by group or site administrators. Thats useful while you are configuring the page.'),
);
Moshe Weitzman
committed
$form['submit'] = array(
'#type' => 'submit',
Moshe Weitzman
committed
'#value' => $did ? t('Update page') : t('Create page'),
Moshe Weitzman
committed
);
$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);
Moshe Weitzman
committed
return $form;
}
Moshe Weitzman
committed
/**
* 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";
Moshe Weitzman
committed
$result = db_query($sql, $nid);
while ($row = db_fetch_object($result)) {
$rows[$row->did] = $row;
}
Moshe Weitzman
committed
if (isset($rows)) {
return $rows;
}
return array();
Moshe Weitzman
committed
}
Moshe Weitzman
committed
/**
* Load an og_panels object.
*
* @param int $did
* @return object $og_panel
*/
Moshe Weitzman
committed
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);
}
Moshe Weitzman
committed
/**
* 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
*/
Moshe Weitzman
committed
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);
Moshe Weitzman
committed
$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.
*
Moshe Weitzman
committed
* @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
*
Moshe Weitzman
committed
* @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');
Moshe Weitzman
committed
$display = panels_load_display($did);
if (is_object($group_node)) {
$display->context = array('og_panels' => ctools_context_create('node', $group_node));
Moshe Weitzman
committed
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) {
Moshe Weitzman
committed
$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'])));
Moshe Weitzman
committed
}
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.'));
Moshe Weitzman
committed
}
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']))) {
Moshe Weitzman
committed
form_error($form['path'], t("That path is currently in use by another one of your group's pages. Please enter another path."));
}
Moshe Weitzman
committed
}
Moshe Weitzman
committed
/**
* INSERT or UPDATE a new og_panel. If insert, redirect to layout form.
*
* Handles tab numbering and path aliases.
*
Moshe Weitzman
committed
* @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.'));
Moshe Weitzman
committed
}
else {
// Create a new display and record that.
$display = panels_new_display();
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.'));
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
$form_state['redirect'] = 'node/'. $form_state['values']['nid']. '/og_panels/'. $display->did .'/panel_layout';
}
}
/**
* 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++;
Moshe Weitzman
committed
}
}
function og_panels_set_breadcrumb($section, $group_node = NULL) {
switch ($section) {
case 'panel_edit':
$bc[] = l(t('Home'), '');
Moshe Weitzman
committed
$bc[] = l(t('Pages'), "node/$group_node->nid/og_panels");
}
drupal_set_breadcrumb($bc);
}
Moshe Weitzman
committed
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.'));
Moshe Weitzman
committed
}
break;
}
}
Moshe Weitzman
committed
// ---------------------------------------------------------------------------
// Meat of the Panels API; almost completely passing through to panels.module
/**
* Pass through to the panels layout editor.
Moshe Weitzman
committed
* @param int $did
* the $did of the og_panel to be edited.
*
Moshe Weitzman
committed
* @param object $group_node
* the node object to which the og_panel is attached.
Moshe Weitzman
committed
*/
function og_panels_edit_layout($did, $group_node) {
og_panels_set_breadcrumb('panel_edit', $group_node);
Moshe Weitzman
committed
$display = og_panels_load_display($did, $group_node); // TODO I don't believe that having the context present is necessary for editing the layout.
Moshe Weitzman
committed
return panels_edit_layout($display, t('Save'), "node/$group_node->nid/og_panels");
}
/**
* Pass through to the panels layout settings editor.
Moshe Weitzman
committed
* @param int $did
* the $did of the og_panel to be edited.
*
Moshe Weitzman
committed
* @param object $group_node
* the node object to which the og_panel is attached.
Moshe Weitzman
committed
*/
function og_panels_edit_layout_settings($did, $group_node) {
og_panels_set_breadcrumb('panel_edit', $group_node);
Moshe Weitzman
committed
$display = og_panels_load_display($did);
Moshe Weitzman
committed
return panels_edit_layout_settings($display, t('Save'), "node/$group_node->nid/og_panels");
}
/**
* Pass through to the panels content editor.
Moshe Weitzman
committed
* @param int $did
* the $did of the og_panel to be edited.
*
Moshe Weitzman
committed
* @param object $group_node
* the node object to which the og_panel is attached.
Moshe Weitzman
committed
*/
function og_panels_edit_content($did, $group_node) {
og_panels_set_breadcrumb('panel_edit', $group_node);
Moshe Weitzman
committed
$display = og_panels_load_display($did, $group_node, TRUE);
Moshe Weitzman
committed
// 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.
Moshe Weitzman
committed
print theme('page', panels_edit($display, "node/$group_node->nid/og_panels", $display->content_types), FALSE);
Moshe Weitzman
committed
}
Moshe Weitzman
committed
function og_panels_admin_content() {
panels_load_include('common');
return drupal_get_form('panels_common_settings', 'og_panels');
}
Moshe Weitzman
committed
/**
* Implementation of hook_panels_contexts()
Moshe Weitzman
committed
*/
function og_panels_panels_contexts() {
include_once './'. drupal_get_path('module', 'og') .'/includes/og.panelscontext.inc';
Moshe Weitzman
committed
$args['group'] = array(
'title' => t('Group'),
Moshe Weitzman
committed
'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;
}
/**
* Implementation of hook_panels_content_types()
*/
Moshe Weitzman
committed
function og_panels_panels_content_types() {
include_once './'. drupal_get_path('module', 'og') .'/includes/og.panelscontent.inc';
Moshe Weitzman
committed
$items['og_mission'] = array(
'title' => t('OG mission'),
'content_types' => 'og_panels_ct_list_mission',
'single' => TRUE, // only provides a single content type
'render callback' => 'og_panels_ct_render_callback_mission',
// 'add callback' => 'og_panels_content_types_add_callback',
// 'edit callback' => 'og_panels_content_types_edit_callback',
'title callback' => 'og_panels_ct_title_callback_mission',
// 'add submit callback' => 'panels_admin_submit_group',
// 'edit submit callback' => 'panels_admin_submit_group',
// 'validate callback' => 'panels_admin_validate_group',
);
$items['og_description'] = array(
'title' => t('OG description'),
'content_types' => 'og_panels_ct_list_description',
'single' => TRUE, // only provides a single content type
'render callback' => 'og_panels_ct_render_callback_description',
'title callback' => 'og_panels_ct_title_callback_description',
Moshe Weitzman
committed
);
$items['og_subscribers'] = array(
'title' => t('OG members'),
'content_types' => 'og_panels_ct_list_subscribers',
'single' => TRUE, // only provides a single content type
'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, // only provides a single content type
'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, // only provides a single content type
'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',
);
Moshe Weitzman
committed
return $items;
Moshe Weitzman
committed
}
Moshe Weitzman
committed
// An implementation of hook_panels_relationships.
include_once './'. drupal_get_path('module', 'og_panels') .'/includes/grouprelationships.inc';
'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;
}
Moshe Weitzman
committed
// An implementation of hook_panels_block_info. We have to prefix with 'og' and not 'og_panels'.
function og_panels_block_info($module, $delta, &$info) {
switch ($delta) {
case 2:
// Provide alternate versions as content items
unset($info);
break;
default:
$info['icon'] = 'images/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;
}
// These blocks do not need group context.
if ($delta == 3 || $delta == 6) {
unset($info['required context']);
}