I am proposing a D7 port of this module and I am willing to do the work.
But before that:
Has anyone started the porting yet?
Are there other modules that perform the same tasks?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

svetlio’s picture

Hi @Norberto Ostallo, is there any progress

Norberto Ostallo’s picture

Hi! I've just started working on it today, but I've already been able to port all the code to Drupal 7.
At the moment this is just a direct port, with no significant improvements a part from what was required to make it work with the new Drupal version.

I was waiting to hear if someone is already working on something similar before submitting a patch, but you can test this initial version.
I also have a couple of ideas on how to improve this module and adding a few module settings, but first I wanted to have it "just work" with D7.

svetlio’s picture

Thanks so much for quick response, we will test and share experiences

Norberto Ostallo’s picture

Here it is the latest version of the porting. I hope someone will test it and return some feedback.
For convenience, I provide it as a patch to the latest version and as a module immediately installable.

boran’s picture

node_to_word-7.x-1.x.tar_.gz worked fine for me.

Now, would be nice to have Windows CRLF in the text download, and a little admin interface to enable it for specific node types: but thats a separate issue. Thanks for the port.

jodym’s picture

Thanks Norberto Ostallo for porting this to drupal 7 works great. How can you enable this for specific content types.. Would like to create separate template and modify that.

Norberto Ostallo’s picture

Node to word is a VERY basic module and it does not have a lot options... I suggest you to try Print module with this sandbox project I was working on for advanced features.

NancyDru’s picture

Status: Active » Needs review

How about adding this to set the control by type and allow the use of alternate view modes for formatting:

/**
 * Implements hook_form_FORM_ID_alter().
 * Add "show links" option to the node edit form.
 */
function node_to_word_form_node_type_form_alter(&$form, $form_state, $form_id) {
//  drupal_set_message("node_to_word_form_alter $form_id.");
  switch ($form_id) {
    // Is this a content type form?
    case 'node_type_form':
      $type = $form['#node_type']->type;

      $form['display']['node_to_word'] = array(
        '#type' => 'fieldset',
        '#title' => t('Node to Word options'),
        '#collapsible' => TRUE,
        '#weight' => -1,
        );

      // Note that the node module will add "_$type" to this field name
      // to become a system variable.
      $form['display']['node_to_word']["node_to_word"] = array(
        '#type' => 'radios',
        '#options' => array(t('No'), t('Yes')),
        '#title' => t('Show "save as word" and "save as text" links?'),
        '#default_value' => variable_get("node_to_word_$type", 0),
        '#attributes' => array('class' => array('container-inline')),
        );

      // Get info about view_modes.
      $entity_info = entity_get_info('node');
      $view_modes = array();
      foreach ($entity_info['view modes'] as $mode => $info) {
        $view_modes[$mode] = t($info['label']);
      }
      // Let the admin pick a view mode that we will use for the output.
      $form['display']['node_to_word']["node_to_word_mode"] = array(
        '#type' => 'radios',
        '#options' => $view_modes,
        '#title' => t('View mode to use for output:'),
        '#default_value' => variable_get("node_to_word_mode_$type", 'full'),
        '#attributes' => array('class' => array('container-inline')),
        );

      return;
  }
}

/**
 * Function for checking if a content type should have a
 * "Save as Word" link or not.
 *
 * @param $type
 *  string: content type to be checked
 *
 * @return
 *  boolean: TRUE if content type should have a link
 */
function node_to_word_enabled($type) {
  return variable_get("node_to_word_$type", 0);
}

/**
 * Theme function for building the Word doc output.
 *
 * @param $variables
 *  array: node to be presented as a Word doc
 *
 * @return
 *  string: valid HTML
 */
function theme_node_to_word_doc_output($variables) {
  $node = $variables['node'];
  $mode = variable_get("node_to_word_mode_$node->type", 'full');

  $build = node_view($node, $mode);

  $build['links']['#access'] = FALSE;

  $output = drupal_render($build);

  return $output;
}

/**
 * Theme function for building the text file output.
 *
 * @param $variables
 *  array: node to be presented as a text file
 *
 * @return
 *  string: valid output
 */
function theme_node_to_word_txt_output($variables) {
  $node = $variables['node'];
  $mode = variable_get("node_to_word_mode_$node->type", 'full');

  $build = node_view($node, 'full');

  $build['links']['#access'] = FALSE;

  $output = drupal_render($build);

  return $output;
}

Note that these settings appear in the "Display settings" tab of the content type edit page.

Phil Owen’s picture

This works beautifully - thanks for your work on this!

I noticed that the export links are packed into the 'links' array. I'd like to remove them and place in node.tpl.php while theming - so I can create, for example, .doc and .txt buttons using icons and place directly below the "submitted" element (where social icons might usually go) or other places in the theme.

How might I go about this?

NOTE: I'm just handy enough with PHP to get myself into trouble. Sometimes I like getting into trouble. :)

NancyDru’s picture

A contributed module shouldn't be in the habit of altering a "core" theme template. It would be better to figure how to use a template just for this module and use that output in the node display.

Phil Owen’s picture

Thanks NancyDru,

I was hoping the module could output a variable or object that I could drop in my theme files (a custom theme - I've overridden the core files properly by copying to theme files) I'd like to have flexibility in placing the module links where I'd like in the theme. Is this bad practice?

Please forgive my limited understanding; I'm pretty solid with theming but not at all with module development.

Anyway, I loosely understand that the following code from the module places the module links in the $links array:

<?php
function node_to_word_node_view($node, $view_mode, $langcode) {
  $links = array();

  if (node_to_word_enabled($node->type)) {
    if (user_access('access node_to_word docs')) {
      $links['node_to_word_link'] = array(
        'title' => t('Save as Word'),
        'href' => "word/$node->nid",
        'attributes' => array('title' => t('Save this document as a Microsoft Word document.'))
      );
      $links['node_to_word_txt_link'] = array(
        'title' => t('Save as text'),
        'href' => "txt/$node->nid",
        'attributes' => array('title' => t('Save this document as a plain text document.'))
      );

      $node->content['links'][$node->type] = array(
        '#theme' => 'links__node__blog',
        '#links' => $links,
        '#attributes' => array('class' => array('links', 'inline')),
      );
    }
  }
}
?>

This has them get packed in with things like the "add new comment" link, which doesn't seem related from a user viewpoint. I'd like the two module links to show under the "submitted" line, along with an "email" share button and "print" button that I'll be placing in the theme.

I'm wondering if it is possible to override the module links' placement in $links with some code in template.php, and then adding something along the lines of: <a href="<?php global $base_url; print $base_url."word/".$node->nid; ?>"><img src="myicon.png"></a> in the theme file.

NancyDru’s picture

If it's just your site, then you can do anything you want. Module developers need to make sure they stick to the "Drupal way."

I think you could put a hook_link_alter() in the template.php and separate out the links before they get rendered.

NancyDru’s picture

function theme_node_to_word_doc_output($variables) {
  $node = $variables['node'];
  $mode = variable_get("node_to_word_mode_$node->type", 'full');

  $build = node_view($node, $mode);

  $build['links']['#access'] = FALSE;

  return $build;
}

No need to force the rendering here, since it will be rendered later by the theme.