| 24 |
return $output; |
return $output; |
| 25 |
case 'admin/modules#description': |
case 'admin/modules#description': |
| 26 |
return t('The book expand module allows admin users to restrict to which books their users are allowed to pages.'); |
return t('The book expand module allows admin users to restrict to which books their users are allowed to pages.'); |
|
//case 'admin/settings/bookexpand': |
|
|
// return t('Select the filter you want to use. Depending on your choice, this is how the parent pages of books will be selected in the drop down options. Note that the Private filter means that nodes that are marked as private will ONLY be visible in the tree structure by the author and required the Private module is installed.'); |
|
| 27 |
} |
} |
| 28 |
} |
} |
| 29 |
|
|
| 36 |
'path' => 'admin/settings/bookexpand', |
'path' => 'admin/settings/bookexpand', |
| 37 |
'title' => 'Book Expansion', |
'title' => 'Book Expansion', |
| 38 |
'description' => t('Decide which filter type to use.'), |
'description' => t('Decide which filter type to use.'), |
| 39 |
'callback' => 'bookexpand_admin_settings', |
'callback' => 'drupal_get_form', |
| 40 |
|
'callback arguments' => array('bookexpand_admin_settings_form'), |
| 41 |
'access' => user_access('administer site configuration'), |
'access' => user_access('administer site configuration'), |
| 42 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
| 43 |
); |
); |
| 81 |
// otherwise add a handbook page |
// otherwise add a handbook page |
| 82 |
else { |
else { |
| 83 |
og_set_group_context($group['nid']); |
og_set_group_context($group['nid']); |
|
$og_public = og_get_visibility_default(); |
|
| 84 |
$node = array('title' => $group['title']. ' '. t('Handbook'), |
$node = array('title' => $group['title']. ' '. t('Handbook'), |
| 85 |
'uid' => $group['uid'], |
'uid' => $group['uid'], |
| 86 |
'type' => 'book', |
'type' => 'book', |
| 87 |
'status' => 1, |
'status' => 1, |
| 88 |
'og_groups' => array($group['nid'] => 1), |
'og_groups' => array($group['nid'] => 1), |
| 89 |
'og_public' => $og_public, |
'og_public' => $group['og_public'], |
| 90 |
'log' => t('automatically created for use within the \'%name\' group', array('%name' => $group_node->title)), |
'log' => t('automatically created for use within the \'%name\' group', array('%name' => $group_node->title)), |
| 91 |
'parent' => 0, |
'parent' => 0, |
| 92 |
'promote' => 0, |
'promote' => 0, |
| 135 |
} |
} |
| 136 |
|
|
| 137 |
/** |
/** |
| 138 |
* Implementation of hook_settings |
* Implementation of a form for the settings for this module |
| 139 |
*/ |
*/ |
|
function bookexpand_admin_settings() { |
|
|
return drupal_get_form('bookexpand_admin_settings_form', $form); |
|
|
} |
|
|
|
|
| 140 |
function bookexpand_admin_settings_form () { |
function bookexpand_admin_settings_form () { |
| 141 |
$options = array ('none' => 'None', 'role' => 'Role', 'user' => 'User'); |
$options = array ('none' => t('None'), 'role' => t('Role'), 'user' => t('User')); |
| 142 |
|
|
| 143 |
if (module_exists('og')) { |
if (module_exists('og')) { |
| 144 |
$options['group'] = 'Group'; |
$options['group'] = t('Group'); |
| 145 |
} |
} |
| 146 |
|
|
| 147 |
if (module_exists('private')) { |
if (module_exists('private')) { |
| 148 |
$options['private'] = 'Private'; |
$options['private'] = t('Private'); |
| 149 |
} |
} |
| 150 |
|
|
| 151 |
$form['bookexpand_filter'] = array( |
$form['bookexpand_filter'] = array( |
| 155 |
'#options' => $options, |
'#options' => $options, |
| 156 |
'#description' => t('Pick which filter you wish to use on the available parent book pages') |
'#description' => t('Pick which filter you wish to use on the available parent book pages') |
| 157 |
); |
); |
| 158 |
|
|
| 159 |
|
$form['bookexpand_default_filter'] = array( |
| 160 |
|
'#type' => 'select', |
| 161 |
|
'#title' => t('Pick a default filter'), |
| 162 |
|
'#description' => t('If a particular filter will not be activated properly, for instance the group filter for a book node outside of the context of a group, choose this option to set a different default filter other than the one for books. This defaults to <em>None</em>.'), |
| 163 |
|
'#options' => array('none' => t('None'), 'user' => t('User')), |
| 164 |
|
'#default_value' => variable_get('bookexpand_default_filter', 'none'), |
| 165 |
|
); |
| 166 |
|
|
| 167 |
|
$form['bookexpand_exclude_user_1'] = array( |
| 168 |
|
'#type' => 'checkbox', |
| 169 |
|
'#title' => t('Exclude user 1'), |
| 170 |
|
'#description' => t('This allows user 1 to see all book pages regardless of origin. However this can become very unwieldy, especially on larger sites.'), |
| 171 |
|
'#default_value' => variable_get('bookexpand_exclude_user_1', TRUE), |
| 172 |
|
); |
| 173 |
|
|
| 174 |
$form['bookexpand_create_handbook_pages'] = array( |
$form['bookexpand_create_handbook_pages'] = array( |
| 175 |
'#type' => 'markup', |
'#type' => 'markup', |
| 176 |
'#value' => '<p>If you click <strong><em>go!</em></strong> then a handbook page for each group you have will be created (assuming it does not already have a handbook page. This can be useful if you have just installed this module, but have a bunch of Organic groups that already have book pages. Do not use this button more than once, since it could have unintended side-effects.</p>'.'<p>'. l('go!', 'admin/bookexpand') .'</p>', |
'#value' => '<p>If you click <strong><em>go!</em></strong> then a handbook page for each group you have will be created (assuming it does not already have a handbook page. This can be useful if you have just installed this module, but have a bunch of Organic groups that already have book pages. Do not use this button more than once, since it could have unintended side-effects.</p>'.'<p>'. l('go!', 'admin/bookexpand') .'</p>', |
| 177 |
); |
); |
| 178 |
|
|
| 179 |
return system_settings_form($form); |
return system_settings_form($form); |
| 180 |
} |
} |
| 181 |
|
|
| 217 |
'#description' => user_access('create new books') ? t('The parent section in which to place this page. Note that each page whose parent is <top-level> is an independent, top-level book.') : t('The parent that this page belongs in.'), |
'#description' => user_access('create new books') ? t('The parent section in which to place this page. Note that each page whose parent is <top-level> is an independent, top-level book.') : t('The parent that this page belongs in.'), |
| 218 |
); |
); |
| 219 |
|
|
| 220 |
// can't let users delete their handbooks by mistake |
// can't let users delete their handbooks by mistake |
| 221 |
if ($node->parent == 0) { |
if ($node->parent == 0) { |
| 222 |
unset($form['delete']); |
unset($form['delete']); |
| 223 |
} |
} |
| 235 |
|
|
| 236 |
break; |
break; |
| 237 |
case 'none': |
case 'none': |
| 238 |
default: |
default: |
| 239 |
$form['parent'] = array( |
$form['parent'] = array( |
| 240 |
'#type' => 'select', |
'#type' => 'select', |
| 241 |
'#title' => t('Parent'), |
'#title' => t('Parent'), |
| 259 |
case 'insert': |
case 'insert': |
| 260 |
if (og_is_group_type($group_node->type)) { |
if (og_is_group_type($group_node->type)) { |
| 261 |
global $user; |
global $user; |
|
$og_public = og_get_visibility_default(); |
|
| 262 |
$node = array('title' => $group_node->title. ' '. t('Handbook'), |
$node = array('title' => $group_node->title. ' '. t('Handbook'), |
| 263 |
'uid' => $user->uid, |
'uid' => $user->uid, |
| 264 |
'type' => 'book', |
'type' => 'book', |
| 265 |
'status' => 1, |
'status' => 1, |
| 266 |
'og_groups' => array($group_node->nid => 1), |
'og_groups' => array($group_node->nid => 1), |
| 267 |
'og_public' => $og_public, |
'og_public' => $group_node->og_public, |
| 268 |
'log' => t('automatically created for use within the \'%name\' group', array('%name' => $group_node->title)), |
'log' => t('automatically created for use within the \'%name\' group', array('%name' => $group_node->title)), |
| 269 |
'parent' => 0, |
'parent' => 0, |
| 270 |
'promote' => 0, |
'promote' => 0, |
| 271 |
'body' => t('This is the front page of your new group handbook. Feel free to edit it.'), |
'body' => t('This is the front page of your new group handbook. Feel free to edit it.'), |
| 272 |
); |
); |
| 273 |
if ($node = node_submit($node)) { |
if ($node = node_submit($node)) { |
| 274 |
$node->uid = $user->uid; |
$node->uid = $user->uid; |
| 275 |
node_save($node); |
node_save($node); |
| 276 |
} |
} |
| 277 |
$sql = "INSERT INTO {og_book} (og_nid, book_nid) VALUES (%d, %d)"; |
$sql = "INSERT INTO {og_book} (og_nid, book_nid) VALUES (%d, %d)"; |
| 293 |
/* |
/* |
| 294 |
* Changes the query to match the chosen filter - This one is by Role |
* Changes the query to match the chosen filter - This one is by Role |
| 295 |
**/ |
**/ |
| 296 |
function bookexpand_toc_role ($exclude = 0) { |
function bookexpand_toc_role($exclude = 0) { |
| 297 |
global $user; |
global $user; |
| 298 |
$uid = $user->uid; |
$uid = $user->uid; |
| 299 |
$rid = array_keys($user->roles); |
$rid = array_keys($user->roles); |
| 300 |
|
|
| 301 |
$r = '('.implode(",", $rid).')'; |
$r = '('.implode(",", $rid).')'; |
| 302 |
|
|
| 303 |
if ($uid==1) { |
// user 1 can see all book pages |
| 304 |
|
if ($uid == 1 && variable_get('bookexpand_exclude_user_1', TRUE)) { |
| 305 |
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.nid <> %d ORDER BY b.weight, n.title'; |
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.nid <> %d ORDER BY b.weight, n.title'; |
| 306 |
} else { |
} |
| 307 |
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM ({node} n INNER JOIN {users_roles} u ON n.uid = u.uid) INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND u.rid IN '.$r.' AND n.nid <> %d ORDER BY b.weight, n.title'; |
// this is too forgiving but that can't be helped. people will just have to make sure that they don't use overlapping roles |
| 308 |
|
else { |
| 309 |
|
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM ({node} n INNER JOIN {users_roles} u ON n.uid = u.uid) INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND u.rid IN '. $r .' AND n.nid <> %d ORDER BY b.weight, n.title'; |
| 310 |
} |
} |
| 311 |
|
|
| 312 |
$output = bookexpand_toc($query, $exclude); |
$output = bookexpand_toc($query, $exclude); |
| 316 |
/* |
/* |
| 317 |
* Changes the query to match the chosen filter - This one is by Group |
* Changes the query to match the chosen filter - This one is by Group |
| 318 |
**/ |
**/ |
| 319 |
function bookexpand_toc_group ($exclude = 0) { |
function bookexpand_toc_group($exclude = 0) { |
| 320 |
global $user; |
global $user; |
| 321 |
$uid = $user->uid; |
$uid = $user->uid; |
| 322 |
$groups = $user->og_groups; |
$groups = $user->og_groups; |
| 323 |
$gid = array_keys($groups); |
$gid = array_keys($groups); |
| 324 |
|
|
| 325 |
if (module_exists('og')) { |
if (module_exists('og') && !($uid == 1 && variable_get('bookexpand_exclude_user_1', TRUE))) { |
| 326 |
if ($group = og_get_group_context()) { |
if ($group = og_get_group_context()) { |
| 327 |
$output = og_book_get_options($group->nid, $exclude); |
return og_book_get_options($group->nid, $exclude); |
| 328 |
} else { |
} |
| 329 |
|
else if (variable_get('bookexpand_default_filter', 'none') == 'user' && !($uid == 1 && variable_get('bookexpand_exclude_user_1', TRUE))) { |
| 330 |
|
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.uid = '. $uid .' AND n.nid <> %d ORDER BY b.weight, n.title'; |
| 331 |
|
} |
| 332 |
|
else { |
| 333 |
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.nid <> %d ORDER BY b.weight, n.title'; |
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.nid <> %d ORDER BY b.weight, n.title'; |
|
$output = bookexpand_toc($query, $exclude); |
|
| 334 |
} |
} |
| 335 |
} else { |
} |
| 336 |
|
else { |
| 337 |
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.nid <> %d ORDER BY b.weight, n.title'; |
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.nid <> %d ORDER BY b.weight, n.title'; |
|
$output = bookexpand_toc($query, $exclude); |
|
| 338 |
} |
} |
| 339 |
|
|
| 340 |
|
$output = bookexpand_toc($query, $exclude); |
| 341 |
|
|
| 342 |
return $output; |
return $output; |
| 343 |
} |
} |
| 344 |
|
|
| 345 |
function og_book_get_options($gid, $exclude = 0) { |
function og_book_get_options($gid, $exclude = 0) { |
| 346 |
$root_nid = og_book_get_root($gid); |
$root_nid = og_book_get_root($gid); |
| 347 |
$row = db_fetch_array(db_query("SELECT b.parent FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.nid = %d", $root_nid)); |
|
| 348 |
if ($row['parent'] == 0) { |
$query = "SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.nid <> %d ORDER BY b.weight, n.title"; |
| 349 |
return array('<'. t('top-level') .'>'); |
|
|
} |
|
|
|
|
|
$query = "SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.nid <> %d ORDER BY b.weight, n.title"; |
|
| 350 |
$toc = bookexpand_toc($query, $exclude, $root_nid); |
$toc = bookexpand_toc($query, $exclude, $root_nid); |
| 351 |
return $toc; |
return $toc; |
| 352 |
} |
} |
| 359 |
/* |
/* |
| 360 |
* Changes the query to match the chosen filter - This one is by User |
* Changes the query to match the chosen filter - This one is by User |
| 361 |
**/ |
**/ |
| 362 |
function bookexpand_toc_user ($nid) { |
function bookexpand_toc_user($nid) { |
| 363 |
global $user; |
global $user; |
| 364 |
$uid = $user->uid; |
$uid = $user->uid; |
| 365 |
|
|
| 366 |
if ($uid != 1) { |
if (!($uid == 1 && variable_get('bookexpand_exclude_user_1', TRUE))) { |
| 367 |
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.uid = '.$uid.' AND n.nid <> %d ORDER BY b.weight, n.title'; |
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.uid = '. $uid .' AND n.nid <> %d ORDER BY b.weight, n.title'; |
| 368 |
} else { |
} |
| 369 |
|
else { |
| 370 |
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.nid <> %d ORDER BY b.weight, n.title'; |
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.nid <> %d ORDER BY b.weight, n.title'; |
| 371 |
} |
} |
| 372 |
$exclude = 0; |
$exclude = 0; |
| 382 |
global $user; |
global $user; |
| 383 |
$uid = $user->uid; |
$uid = $user->uid; |
| 384 |
|
|
| 385 |
if (module_exists('private')) { |
if (module_exists('private') && !($uid == 1 && variable_get('bookexpand_exclude_user_1', TRUE))) { |
| 386 |
$query = "SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid INNER JOIN {private} p ON n.nid = p.nid WHERE n.status = 1 AND p.private <> 1 OR p.nid = ANY (SELECT no.nid FROM {node} no WHERE no.uid = $uid) AND n.nid <> %d ORDER BY b.weight, n.title"; |
$query = "SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid INNER JOIN {private} p ON n.nid = p.nid WHERE n.status = 1 AND p.private <> 1 OR p.nid = ANY (SELECT no.nid FROM {node} no WHERE no.uid = $uid) AND n.nid <> %d ORDER BY b.weight, n.title"; |
| 387 |
} else { |
} |
| 388 |
|
else if (variable_get('bookexpand_default_filter', 'none') == 'user' && !($uid == 1 && variable_get('bookexpand_exclude_user_1', TRUE))) { |
| 389 |
|
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.uid = '. $uid .' AND n.nid <> %d ORDER BY b.weight, n.title'; |
| 390 |
|
} |
| 391 |
|
else { |
| 392 |
// User 1 can see all choices. |
// User 1 can see all choices. |
| 393 |
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.nid <> %d ORDER BY b.weight, n.title'; |
$query = 'SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.nid <> %d ORDER BY b.weight, n.title'; |
| 394 |
} |
} |
| 414 |
if ($nid) { |
if ($nid) { |
| 415 |
$sql = "SELECT n.title FROM {node} n WHERE n.nid = %d AND n.nid <> %d"; |
$sql = "SELECT n.title FROM {node} n WHERE n.nid = %d AND n.nid <> %d"; |
| 416 |
$toc = array(); |
$toc = array(); |
| 417 |
// If the user has permission to create new books, add the top-level book page to the menu; |
$result = db_query($sql, $nid, $exclude); |
| 418 |
if (user_access('create new books')) { |
|
| 419 |
$toc[0] = '<'. t('top-level') .'>'; |
while ($row = db_fetch_array($result)) { |
| 420 |
|
$toc[$nid] = $row['title']; |
| 421 |
} |
} |
| 422 |
$row = db_fetch_array(db_query($sql, $nid, $exclude)); |
} |
| 423 |
$toc[$nid] = $row['title']; |
else { |
|
} else { |
|
| 424 |
$toc = array(); |
$toc = array(); |
| 425 |
// If the user has permission to create new books, add the top-level book page to the menu; |
// If the user has permission to create new books, add the top-level book page to the menu; |
| 426 |
if (user_access('create new books')) { |
if (user_access('create new books') && variable_get('bookexpand_filter', 'none') != 'group') { |
| 427 |
$toc[0] = '<'. t('top-level') .'>'; |
$toc[0] = '<'. t('top-level') .'>'; |
| 428 |
} |
} |
| 429 |
} |
} |
| 433 |
return $toc; |
return $toc; |
| 434 |
} |
} |
| 435 |
|
|
|
?> |
|