function book_made_simple_nodeapi in Book made simple 6.3
Implementation of hook_nodeapi().
File
- ./
book_made_simple.module, line 638
Code
function book_made_simple_nodeapi(&$node, $op, $teaser, $page) {
if (empty($node->book["bid"])) {
$type = $node->type;
switch ($op) {
// Node creation
case 'insert':
$max_depth = variable_get('book_made_simple_limit_depth', 99);
if ((user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $type) && $node->book['depth'] < $max_depth) {
$bookTypes = variable_get('book_made_simple_auto_main_page', array());
$bookType = $bookTypes[$type];
$toCreate = false;
if (null != $bookType && $bookType != "0") {
$toCreate = true;
}
if ($toCreate && !isset($_GET['parent'])) {
$node->book["bid"] = $node->nid;
$node->book['nid'] = $node->nid;
$node->book['module'] = 'book';
$node->book['menu_name'] = book_menu_name($node->book['bid']);
$node->book['options'] = array(
'type' => $node->type,
);
_book_update_outline($node);
}
}
break;
// Hack for translation module. Adding parent property to automatically select parent book.
case "prepare translation":
$translation = $node->translation_source;
if (isset($translation->book) && !isset($_GET["parent"])) {
// get parent menu link for the node + language
$plid = $translation->book['plid'];
$parentPage = book_link_load($plid);
if (isset($parentPage) && $parentPage > 0) {
$pnid = $parentPage['nid'];
if (isset($pnid) && $pnid != "") {
$query = "SELECT bid, mlid FROM {node} n left join {book} b on b.nid = n.nid where tnid= {$pnid} and language='" . $node->language . "'";
$translatedParent = db_fetch_object(db_query($query));
if ($translatedParent) {
$mlid = $translatedParent->mlid;
$params = array();
$params[] = "parent={$mlid}";
foreach ($_GET as $key => $value) {
if ($key == "q") {
$path = $value;
}
else {
$params[] = $key . "=" . $value;
}
}
$queryString = implode("&", $params);
drupal_goto($path, $queryString);
$ok = true;
}
else {
drupal_set_message(t("This node has no translated parent, so no book selected"), "warning");
}
}
}
}
break;
}
}
else {
switch ($op) {
// Hide standard add Child link
case 'alter':
if ($node->links) {
if (variable_get('book_made_simple_hide_default_add_child', true)) {
if (array_key_exists("book_add_child", $node->links)) {
unset($node->links["book_add_child"]);
}
}
$position = variable_get("book_made_simple_child_list_style_position", "FIRST");
if ($position == "FIRST") {
if (array_key_exists("book_made_simple", $node->links)) {
$a = $node->links["book_made_simple"];
unset($node->links["book_made_simple"]);
array_unshift($node->links, $a);
}
}
break;
}
}
}
}