Any plans to port this module to 6.x?

CommentFileSizeAuthor
#6 easylink_6.patch7.19 KBdawehner
#1 easylink_6.patch6.88 KBdawehner
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

FileSize
6.88 KB
dawehner’s picture

Status: Active » Needs review
dawehner’s picture

change to code needs review

drupaloSa’s picture

Status: Needs work » Needs review

Because of the Views api changes, the patch is not enough to make the module work with Views2. So after you apply the patch, you'll get fatal error messages saying some views function could not be found. I tried to modify the patch to reflect the views api changes in the easylink_loader function. There was also some problems with the settings page. Now the both the settings page and the pop-up views window works. However, i couldn't make the onclick action work. When i click a node in the list, the window is closed but the link is not added to the text area. I'll attach my code below, perhaps you can sort out this problem:

<?php
// $Id: easylink.module,v 1.3.2.6 2007/10/12 15:48:56 linuxbox Exp $

/**
 * Implementation of hook_help().
 */
function easylink_help($page, $arg) {
  switch ($page) {
    case 'admin/help#easylink';
      return t('Enables users easily add links within TinyMCE.');
    case 'admin/settings/easylink':
      return t('Here you can configure the view easylink uses to provide the list of nodes within TinyMCE.  To change the configuration of the view visit the Views <a href="!url" >configuration page</a>.', array('!url' => url('admin/build/views')));
  }
}

/**
 * Implementation of hook_menu().
 */
function easylink_menu() {
  $items = array();
  $items['easylink/load'] = array(
    'title' => 'EasyLink',
    'page callback' => 'easylink_loader',
    'access callback' => 'user_access',
    'access arguments' => array('access tinymce'),            
    'type' => MENU_CALLBACK);

  $items['admin/settings/easylink'] = array(
    'title' => 'EasyLink',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('easylink_admin_settings'),
    'access callback' => 'user_access',
    'access arguments' => array('administer tinymce'),         
    'description' => 'Change the view Easylink uses to display nodes to the user',
    'type' => MENU_NORMAL_ITEM);
  return $items;
}

 /**
+ * Implementation of hook_init().
+ * @see hook_init
+ */ 
function easylink_init(){
  $path = drupal_get_path('module', 'easylink');

  // the base url here is used for popup windows

  drupal_add_js("var BASE_URL = \"". base_path() ."\";\n", 'inline'); 
}


/**
 * Print the main easylink interface
 */
function easylink_loader() {

  $editor = arg(2) ? arg(2) : 'textarea';

  $title = t('EasyLink');
  $bp = base_path();
  $output  = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN">' . "\n";
  $output .= "<html>\n";
  $output .= "<head>\n";
  $output .= "<title>EasyLink</title>\n";
  $output .= '<style type="text/css" media="all">@import "'.$bp.'misc/drupal.css";</style>';
  $output .= '<style type="text/css" media="all">@import "'.$bp.path_to_theme().'/style.css";</style>';
  $output .= '<style type="text/css">#pager {text-align: left; }</style>';
  $output .= "\n<script type=\"text/javascript\"><!--\n";
  $output .= "  var BASE_URL = \"" . base_path() . "\";\n";
  $output .= "--></script>\n";

  $path = drupal_get_path('module', 'easylink');
  $tinymce_path = drupal_get_path('module', 'tinymce');
  $tinymce_js = base_path() . $tinymce_path . '/tinymce/jscripts/tiny_mce/tiny_mce_popup.js';
  $easylink_js = base_path() . $tinymce_path . '/tinymce/jscripts/tiny_mce/plugins/easylink/jscripts/easylink.js';

  $output .= "<script type=\"text/javascript\" src=\"$tinymce_js\"></script>\n"; // splitting the tag helps Dreamweaver color coding
  $output .= "<script type=\"text/javascript\" src=\"$easylink_js\"></script>\n";

  $output .= "</head>\n\n";
  $output .= '<html><div id="content"><div id="main"><div class="mw1">';

  // Load view
  $myview = views_get_view(variable_get('easylink_view', 'easylink'));
  // Override url to support views filters
  $myview->url = "easylink/load";
  // Build view
  $args = array();
  $myview->set_arguments($args);
  //$myview->execute(); 
  //$view_text = $myview->result;  
  $view_text = $myview->render();
  //$view_text = views_build_view('embed', $myview, FALSE, TRUE, $myview->nodes_per_page);

  // Add javascript onClick action to insert link except on pager links
  $view_text = preg_replace_callback('/<a href=".*">/i', "check_pager", $view_text);
  $output .= '<div class="easylink">' . $view_text . '</div>';
  $output .= "</div></div></div></html>\n";
  
  print $output;
}

// Check if link is a pager link or not.  Only replace non-pager links
function check_pager($matches){
  foreach ($matches as $match){
    if (preg_match('/.*\?page=/', $match)||preg_match('/.*\?sort=/', $match)){
      return $match;
    } else {
      // Reg-ex fix from Jose San Martin
      $search = '/<a href="(.*?)"[^>]*>/i';
      $replace = '<a href="javascript:void(0);" onClick="addLink(\'$1\')">'; 
      return preg_replace($search, $replace, $match);
    }
  }
}

// Implementation of hook_settings()
function easylink_admin_settings() {
  $result = db_query("SELECT name, description FROM {views_view}");
  while ($view = db_fetch_object($result)) {
    $views[$view->name] = $view->name . ': ' . $view->description;
  }

  views_include_default_views ();
  $default_views = views_discover_default_views();
  $views_status = variable_get('views_defaults', array());
  foreach ($default_views as $view) {
    if (!$views[$view->name] &&
      ($views_status[$view->name] == 'enabled' || (!$views_status[$view->name] && !$view->disabled))) {
      $views[$view->name] = check_plain($view->name);
    }
  }

  ksort($views);
  $current_view = variable_get('easylink_view', 'easylink');

  $form['easylink_view'] = array(
    '#type' => 'select',
    '#options' => $views,
    '#title' => t('Choose a view to use with easylink'),
    '#default_value' => $current_view,
  );

  return system_settings_form($form);
}

function easylink_views_default_views(){
  $view = new view;
  $view->name = 'Easylink';
  $view->description = 'easylink view';
  $view->tag = 'node, link';
  $view->view_php = '';
  $view->base_table = 'node';
  $view->is_cacheable = FALSE;
  $view->api_version = 2;
  $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  $handler = $view->new_display('default', 'Defaults', 'default');
  $handler->override_option('fields', array(
    'title' => array(
      'label' => 'Titel',
      'link_to_node' => 1,
      'exclude' => 0,
      'id' => 'title',
      'table' => 'node',
      'field' => 'title',
      'relationship' => 'none',
    ),
  ));
  $handler->override_option('filters', array(
    'type' => array(
      'operator' => 'in',
      'value' => array(
        'page' => 'page',
      ),
      'group' => '0',
      'exposed' => FALSE,
      'expose' => array(
        'operator' => FALSE,
        'label' => '',
      ),
      'id' => 'type',
      'table' => 'node',
      'field' => 'type',
      'relationship' => 'none',
    ),
    'uid_current' => array(
      'operator' => '=',
      'value' => 1,
      'group' => '0',
      'exposed' => FALSE,
      'expose' => array(
        'operator' => FALSE,
        'label' => '',
      ),
      'id' => 'uid_current',
      'table' => 'users',
      'field' => 'uid_current',
      'relationship' => 'none',
    ),
  ));
  $handler->override_option('access', array(
    'type' => 'none',
    'role' => array(),
    'perm' => '',
  ));
  $handler->override_option('title', 'Easylink');
  $handler->override_option('use_ajax', TRUE);
  $handler->override_option('use_pager', '1');
  $handler->override_option('style_plugin', 'table');
  $handler->override_option('style_options', array(
    'grouping' => '',
    'override' => 1,
    'sticky' => 1,
    'order' => 'asc',
    'columns' => array(
      'title' => 'title',
    ),
    'info' => array(
      'title' => array(
        'sortable' => 1,
        'separator' => '',
      ),
    ),
    'default' => 'title',
  ));
  $handler = $view->new_display('page', 'Seite', 'page_1');
  $handler->override_option('items_per_page', 50);
  $handler->override_option('use_pager', '1');
  $handler->override_option('path', 'easylink');
  $handler->override_option('menu', array(
    'type' => 'none',
    'title' => '',
    'weight' => 0,
  ));
  $handler->override_option('tab_options', array(
    'type' => 'none',
    'title' => '',
    'weight' => 0,
  ));
  // Add view to list of views to provide.
  $views[$view->name] = $view;

  // ...Repeat all of the above for each view the module should provide.

  // At the end, return array of default views.
  
  return $views;
}
drupaloSa’s picture

Status: Needs review » Needs work

changing the issue status

dawehner’s picture

Status: Needs review » Needs work
FileSize
7.19 KB

Wow thats mhh.. i extra looked at http://views.doc.logrus.com/group__views__hooks.html wether this hook changed

and in addition i had a old version of views installed in my test enviroment

drupaloSa’s picture

To clarify this, is this patch supposed to work with Views2?

And also it seems that you're using an Easylink version dated 29 Aug 2007. However, the latest release is 2007-Dec-01.

StevenWill’s picture

There is a difference in the easylink.module from AUG and DEC and I do not have access to a Aug version. dereine, would you mind attaching a zip file of the easylink version you are patching?

jrb’s picture

zmove’s picture

Subscribe

Instead of TinyMCE module that is near to the death, it would be nice to see it integrated with WYSIWYG API (which support TinyMCE) and that try to standardize only one API to easily add and configure all WYSIWYG editor for drupal.

johnhanley’s picture

I have a pressing need for the Drupal 6 version of this module. What's the status of the port?

Summit’s picture

+1 for also FCKeditor or WYSIWYG API support on D6
Subscribing, greetings, Martijn

robbertnl’s picture

Subscribing also for support on D6.

nikolajb’s picture

Same here. Using TinyMCE on Wysiwyg and looking for a nice clean way to link to nodes, preferably one that doesn't give me trouble if I change the clean URLs / path to a node.

From what I see, the TinyMCE module is either dead or dying for D6. Wysiwyg module is the future, and also opens the door to the other editors out there :)

tronathan’s picture

The following module provides similar functionality for Drupal 6.x only:

http://drupal.org/project/tinymce_node_picker

David.W’s picture

Subscribing also for support on D6.