You are here

function _revisioning_load_op in Revisioning 7

Same name and namespace in other branches
  1. 8 revisioning.module \_revisioning_load_op()
  2. 6.4 revisioning.module \_revisioning_load_op()
  3. 6.3 revisioning.module \_revisioning_load_op()

Load a revision.

Assuming that the node passed in is the current revision (core default), this function determines whether the lastest revision should be loaded instead, in which case it returns REVISIONING_LOAD_LATEST.

Parameters

object $node: only nodes of content types subject to moderation are processed by this function

string $op: either 'edit' or 'view'

bool $check_access: whether revision access permissions should be checked; if the user has no permission to load the latest revisions, then the function returns REVISIONING_LOAD_CURRENT

Return value

int REVISIONING_LOAD_LATEST or REVISIONING_LOAD_CURRENT

4 calls to _revisioning_load_op()
_revisioning_edit in ./revisioning.module
Callback for the primary Edit tab.
_revisioning_title_for_tab in ./revisioning.module
Callback for the primary View, Edit and Revisions tabs titles.
_revisioning_view in ./revisioning.module
Menu callback for the primary View tab.
_revisioning_view_edit_access_callback in ./revisioning.module
Access callback function.

File

./revisioning.module, line 1070
Allows content to be updated and reviewed before submitting it for publication, while the current live revision remains unchanged and publicly visible until the changes have been reviewed and found fit for publication by a moderator.

Code

function _revisioning_load_op($node, $op, $check_access = TRUE) {
  if (!empty($node->revision_moderation)) {
    $view_mode = (int) variable_get('revisioning_view_callback', REVISIONING_LOAD_CURRENT);
    $edit_mode = (int) variable_get('revisioning_edit_callback', REVISIONING_LOAD_CURRENT);
    $load_op = $op == 'edit' ? $edit_mode : $view_mode;
    if ($load_op == REVISIONING_LOAD_LATEST) {

      // Site is configured to load latest revision, but we'll only do this if
      // the latest isn't loaded already and user has the permission to do so.
      $latest_vid = revisioning_get_latest_revision_id($node->nid);
      if ($latest_vid != $node->current_revision_id) {
        if (!$check_access) {
          return REVISIONING_LOAD_LATEST;
        }
        $original_vid = $node->vid;
        $node->vid = $latest_vid;
        $node->is_current = revisioning_revision_is_current($node);
        $revision_op = $op == 'view' ? 'view revisions' : 'edit revisions';
        $access = _revisioning_access_node_revision($revision_op, $node);

        // Restore $node (even though called by value), to remain consistent.
        $node->vid = $original_vid;
        $node->is_current = revisioning_revision_is_current($node);
        if ($access) {
          return REVISIONING_LOAD_LATEST;
        }
      }
    }
  }
  return REVISIONING_LOAD_CURRENT;
}