*************** *** 1,236 **** - 1); - - // determine access - $access = FALSE; - if (is_numeric(arg(3)) && 'view' == arg(4)) { - $access = $view_tagged_revisions; - } - else { - $access = ($administer_nodes || $tag_revisions) && $more_than_one; - } - - $items[] = array('path' => 'node/'. arg(1) .'/revision_tags', 'title' => t('Revision tags'), - 'callback' => 'revisiontags_localtask', - 'access' => $access, - 'weight' => 3, - 'callback arguments' => array(arg(1), arg(3) ? arg(3) : NULL, arg(4) ? arg(4) : 'overview'), - 'type' => $tag_revisions ? MENU_LOCAL_TASK : MENU_CALLBACK); - } - } - return $items; - } - - /** - * hook perm - */ - function revisiontags_perm() { - return array('tag revisions', 'view tagged revisions'); - } - - /** - * Callback for the revision tags tab on node pages. - */ - function revisiontags_localtask($nid, $vid = NULL, $op = 'overview') { - if ('view' == $op) { - if (!user_access('view tagged revisions')) { - drupal_access_denied(); - return; - } - } - else if (!user_access('administer nodes') && !user_access('tag revisions')) { - drupal_access_denied(); - return; - } - - switch ($op) { - case 'overview': - $node = node_load($nid); - return revisiontags_overview($node); - case 'view': - if (is_numeric($vid)) { - $node = node_load($nid, $vid); - if ($node->nid) { - if (node_access('view', $node)) { - $revisiontag = _get_revision_tag($node->nid, $vid); - if (!empty($revisiontag) && !empty($revisiontag->tag)) { - drupal_set_title(t('%title (Tag: %tag)', array('%title' => $node->title, '%tag' => $revisiontag->tag))); - } - else { - drupal_set_title(t('Revision of %title from %date', array('%title' => $node->title, '%date' => format_date($node->revision_timestamp)))); - } - // The second argument to node_show is the comment id... so we give it NULL. This defaults to - // 0 when it reaches comment_render. Death to node_show! - return node_show($node, NULL); - } - drupal_access_denied(); - return; - } - } - break; - case 'edit': - if (is_numeric($vid)) { - $node = node_load($nid); - if (!empty($node->nid)) { - $revisiontag = _get_revision_tag($node->nid, $vid); - $revisiontag->current_vid = $node->vid; - if (!empty($revisiontag->tag)) { - drupal_set_title(t('%title (Tag: %tag)', array('%title' => $node->title, '%tag' => $revisiontag->tag))); - } - else { - drupal_set_title(t('Revision of %title from %date', array('%title' => $node->title, '%date' => format_date($node->revision_timestamp)))); - } - return drupal_get_form('revisiontags_edit', $revisiontag); - } - } - break; - } - } - - function revisiontags_overview($node) { - drupal_set_title(t('Revisions for %title', array('%title' => $node->title))); - - $header = array(t('Revision'), t('Tag'), t('Public'), array('data' => t('Operations'), 'colspan' => 2)); - - $revisions = node_revision_list($node); - $rows = array(); - foreach ($revisions as $revision) { - $row = array(); - $operations = array(); - $tag = array(''); - $public = array(''); - $revisiontag = _get_revision_tag($node->nid, $revision->vid); - if (!empty($revisiontag)) { - $tag = array($revisiontag->tag); - if (!empty($revisiontag->tag) && $revisiontag->public == 1) { - $public = array(t('public')); - } - } - $row[] = t('!date by !username', array('!date' => l(format_date($revision->timestamp, 'small'), "node/$node->nid/revisions/$revision->vid/view"), '!username' => theme('username', $revision))) - . (($revision->log != '') ? '
'. filter_xss($revision->log) .'
' : ''); - $operations[] = l(t('edit'), "node/$node->nid/revision_tags/$revision->vid/edit"); - $rows[] = array_merge($row, $tag, $public, $operations); - } - $output .= theme('table', $header, $rows); - - return $output; - } - - /** - * revision tag editing form - */ - function revisiontags_edit($revisiontag) { - $form['tag'] = array( - '#type' => 'textfield', - '#title' => t('Tag of the revision'), - '#default_value' => $revisiontag->tag, - ); - $form['public'] = array( - '#type' => 'checkbox', - '#title' => t('Is this a tagged revision that is available to the public?'), - '#description' => t('The current revision will always be public'), - '#default_value' => isset($revisiontag->public) ? $revisiontag->public : 1, - ); - if ($revisiontag->current_vid == arg(3)) { - $form['public']['#default_value'] = 1; - $form['public']['#disabled'] = TRUE; - } - $form['submit'] = array( - '#type' => 'submit', - '#default_value' => t('Save'), - ); - $form['#redirect'] = arg(0) .'/'. arg(1) .'/'. arg(2) .'/'. arg(3); - return $form; - } - - function revisiontags_edit_submit($form_id, $form) { - $node = node_load(arg(1)); - if ($node->vid == arg(3)) { - $form['public'] = 1; - } - - // If revision_tags_unique is TRUE, enforce the uniqueness of this tag - if (variable_get('revision_tags_unique', TRUE)) { - db_query("DELETE FROM {revision_tags} WHERE nid = %d AND tag = '%s'", arg(1), $form['tag']); - } - - $revisiontag = _get_revision_tag(arg(1), arg(3)); - if (empty($revisiontag)) { - db_query("INSERT INTO {revision_tags} (nid, vid, tag, public) VALUES(%d, %d, '%s', %d)", arg(1), arg(3), $form['tag'], $form['public']); - } - else { - db_query("UPDATE {revision_tags} SET tag = '%s', public = %d WHERE nid = %d AND vid = %d", $form['tag'], $form['public'], arg(1), arg(3)); - } - } - - function revisiontags_block($op = 'list', $delta = 0, $edit = array()) { - if ($op == 'list') { - $blocks[0] = array('info' => t('Tagged revisions')); - return $blocks; - } - else if ($op == 'view' && (user_access('tag revisions') || user_access('view tagged revisions'))) { - switch($delta) { - case 0: - // try to infer the nid from the path - if (arg(0) == 'node' && is_numeric(arg(1))) { - $nid = arg(1); - } - else { - // we didn't figure it out, so get out of here - return; - } - - // Load the node to get the current revision (the node is getting loaded - // anyway, so it will be pulled from the static cache) - $node = node_load($nid); - - // Get the revision tags - $rs = db_query("SELECT vid, tag FROM {revision_tags} WHERE nid = %d AND public = 1", $nid); - $list = array(); - while($row = db_fetch_object($rs)) { - if ($row->vid == $node->vid) { - $list[] = l($row->tag, "node/$nid"); - } - else { - $list[] = l($row->tag, "node/$nid/revision_tags/$row->vid/view"); - } - } - - // generate the content for the block - $content = ''; - if (count($list) > 1) { - $content = theme('revisiontags_tags', $list); - } - $block = array('subject' => t('Versions available'), - 'content' => $content); - break; - } - return $block; - } - } - - function theme_revisiontags_tags($list) { - return theme('item_list', $list); - } - - /** - * Gives back the tag of a revision - */ - function _get_revision_tag($nid, $vid) { - $result = db_fetch_object(db_query("SELECT tag, public FROM {revision_tags} WHERE nid = %d AND vid = %d", $nid, $vid)); - if (!empty($result)) { - $result->tag = trim($result->tag); - } - return $result; - } --- 1,258 ---- + 'Revision tags', + 'page callback' => 'revisiontags_localtask', + 'page arguments' => array(1, 3, 4), + 'access callback' => 'revisiontags_access', + 'access arguments' => array(1), + 'type' => MENU_LOCAL_TASK + ); + $items['node/%node/revision_tags/%/view'] = array( + 'title' => 'View Revision tags', + 'page callback' => 'revisiontags_localtask', + 'page arguments' => array(1, 3, 4), + 'access callback' => 'revisiontags_access', + 'access arguments' => array(1,4), + 'type' => MENU_CALLBACK + ); + return $items; + } + + /** + * hook perm + */ + function revisiontags_perm() { + return array('tag revisions', 'view tagged revisions'); + } + + function revisiontags_access($node, $op = NULL) { + $administer_nodes = user_access('administer nodes'); + $tag_revisions = user_access('tag revisions'); + $view_tag_revisions = user_access('view tagged revisions'); + if ($op == 'view') { + $access = ($administer_nodes || $view_tag_revisions); + } + else { + // various permissions + $more_than_one = (db_result(db_query('SELECT COUNT(*) FROM {node_revisions} WHERE nid = %d', $node->nid)) > 1); + $access = ($administer_nodes || $tag_revisions) && $more_than_one; + } + return $access; + } + + + /** + * Callback for the revision tags tab on node pages. + */ + function revisiontags_localtask($node, $vid = NULL, $op = 'overview') { + $nid = $node->nid; + if ($op == '') $op = 'overview'; + if ('view' == $op) { + if (!user_access('view tagged revisions')) { + drupal_access_denied(); + return; + } + } + else if (!user_access('administer nodes') && !user_access('tag revisions')) { + drupal_access_denied(); + return; + } + + switch ($op) { + case 'overview': + $node = node_load($nid); + return revisiontags_overview($node); + case 'view': + if (is_numeric($vid)) { + $node = node_load($nid, $vid); + if ($node->nid) { + if (node_access('view', $node)) { + $revisiontag = _get_revision_tag($node->nid, $vid); + if (!empty($revisiontag) && !empty($revisiontag->tag)) { + drupal_set_title(t('%title (Tag: %tag)', array('%title' => $node->title, '%tag' => $revisiontag->tag))); + } + else { + drupal_set_title(t('Revision of %title from %date', array('%title' => $node->title, '%date' => format_date($node->revision_timestamp)))); + } + // The second argument to node_show is the comment id... so we give it NULL. This defaults to + // 0 when it reaches comment_render. Death to node_show! + return node_show($node, NULL); + } + drupal_access_denied(); + return; + } + } + break; + case 'edit': + if (is_numeric($vid)) { + $node = node_load($nid); + if (!empty($node->nid)) { + $revisiontag = _get_revision_tag($node->nid, $vid); + $revisiontag->current_vid = $node->vid; + if (!empty($revisiontag->tag)) { + drupal_set_title(t('%title (Tag: %tag)', array('%title' => $node->title, '%tag' => $revisiontag->tag))); + } + else { + drupal_set_title(t('Revision of %title from %date', array('%title' => $node->title, '%date' => format_date($node->revision_timestamp)))); + } + return drupal_get_form('revisiontags_edit', $revisiontag); + } + } + break; + } + } + + function revisiontags_overview($node) { + drupal_set_title(t('Revisions for %title', array('%title' => $node->title))); + + $header = array(t('Revision'), t('Tag'), t('Public'), array('data' => t('Operations'), 'colspan' => 2)); + + $revisions = node_revision_list($node); + $rows = array(); + foreach ($revisions as $revision) { + $row = array(); + $operations = array(); + $tag = array(''); + $public = array(''); + $revisiontag = _get_revision_tag($node->nid, $revision->vid); + if (!empty($revisiontag)) { + $tag = array($revisiontag->tag); + if (!empty($revisiontag->tag) && $revisiontag->public == 1) { + $public = array(t('public')); + } + } + $row[] = t('!date by !username', array('!date' => l(format_date($revision->timestamp, 'small'), "node/$node->nid/revisions/$revision->vid/view"), '!username' => theme('username', $revision))) + . (($revision->log != '') ? ''. filter_xss($revision->log) .'
' : ''); + $operations[] = l(t('edit'), "node/$node->nid/revision_tags/$revision->vid/edit"); + $rows[] = array_merge($row, $tag, $public, $operations); + } + $output .= theme('table', $header, $rows); + + return $output; + } + + /** + * revision tag editing form + */ + function revisiontags_edit($form_id, $revisiontag) { + $form['tag'] = array( + '#type' => 'textfield', + '#title' => t('Tag of the revision'), + '#default_value' => $revisiontag->tag, + ); + $form['public'] = array( + '#type' => 'checkbox', + '#title' => t('Is this a tagged revision that is available to the public?'), + '#description' => t('The current revision will always be public'), + '#default_value' => isset($revisiontag->public) ? $revisiontag->public : 1, + ); + if ($revisiontag->current_vid == arg(3)) { + $form['public']['#default_value'] = 1; + $form['public']['#disabled'] = TRUE; + } + $form['submit'] = array( + '#type' => 'submit', + '#default_value' => t('Save'), + ); + $form['#redirect'] = arg(0) .'/'. arg(1) .'/'. arg(2) .'/'. arg(3); + return $form; + } + + function revisiontags_edit_submit($form_id, $form) { + $node = node_load(arg(1)); + if ($node->vid == arg(3)) { + $form['values']['public'] = 1; + } + + // If revision_tags_unique is TRUE, enforce the uniqueness of this tag + if (variable_get('revision_tags_unique', TRUE)) { + db_query("DELETE FROM {revision_tags} WHERE nid = %d AND tag = '%s'", arg(1), $form['values']['tag']); + } + + $revisiontag = _get_revision_tag(arg(1), arg(3)); + if (empty($revisiontag)) { + db_query("INSERT INTO {revision_tags} (nid, vid, tag, public) VALUES(%d, %d, '%s', %d)", arg(1), arg(3), $form['values']['tag'], $form['values']['public']); + } + else { + db_query("UPDATE {revision_tags} SET tag = '%s', public = %d WHERE nid = %d AND vid = %d", $form['values']['tag'], $form['values']['public'], arg(1), arg(3)); + } + } + + function revisiontags_block($op = 'list', $delta = 0, $edit = array()) { + if ($op == 'list') { + $blocks[0] = array('info' => t('Tagged revisions')); + return $blocks; + } + else if ($op == 'view' && (user_access('tag revisions') || user_access('view tagged revisions'))) { + switch($delta) { + case 0: + // try to infer the nid from the path + if (arg(0) == 'node' && is_numeric(arg(1))) { + $nid = arg(1); + } + else { + // we didn't figure it out, so get out of here + return; + } + + // Load the node to get the current revision (the node is getting loaded + // anyway, so it will be pulled from the static cache) + $node = node_load($nid); + + // Get the revision tags + $rs = db_query("SELECT vid, tag FROM {revision_tags} WHERE nid = %d AND public = 1", $nid); + $list = array(); + while($row = db_fetch_object($rs)) { + if ($row->vid == $node->vid) { + $list[] = l($row->tag, "node/$nid"); + } + else { + $list[] = l($row->tag, "node/$nid/revision_tags/$row->vid/view"); + } + } + + // generate the content for the block + $content = ''; + if (count($list) > 1) { + $content = theme('revisiontags_tags', $list); + } + $block = array('subject' => t('Versions available'), + 'content' => $content); + break; + } + return $block; + } + } + + function theme_revisiontags_tags($list) { + return theme('item_list', $list); + } + + /** + * Implementation of hook_theme() + */ + function revisiontags_theme() { + return array( + 'revisiontags_tags' => array( + 'function' => 'theme_revisiontags_tags', + 'arguments' => array('list' => NULL), + ), + ); + } + + /** + * Gives back the tag of a revision + */ + function _get_revision_tag($nid, $vid) { + $result = db_fetch_object(db_query("SELECT tag, public FROM {revision_tags} WHERE nid = %d AND vid = %d", $nid, $vid)); + if (!empty($result)) { + $result->tag = trim($result->tag); + } + return $result; + }