Commit e836d800 authored by Henri MEDOT's avatar Henri MEDOT
Browse files

Synced 7.x-2.x with 6.x-2.x:

Moved the MySQL checks to the functions where they make sense.

Removed unnecessary table aliases in ckeditor_link.menu.inc.

menu and i18nmenu types now implement hook_ckeditor_link_TYPE_revert() to revert paths added through menu links.

Filled README.txt
parent c0837366
CKEDITOR LINK - A PLUGIN TO EASILY CREATE LINKS TO DRUPAL INTERNAL PATHS
http://drupal.org/project/ckeditor_link
REQUIREMENTS
The CKEditor module or the Wysiwyg module
The CKEditor editor
Clean URLs need to be enabled.
INSTALLATION
Please read instructions at: http://drupal.org/project/ckeditor_link
Copy the ckeditor_link folder to your sites/all/modules directory.
Go to admin/modules and enable the module.
*Set permissions*
Go to admin/people/permissions and grant the CKEditor Link related permissions
to the desired roles.
*When using the CKEditor module*
Go to admin/config/content/ckeditor and edit the desired profile.
Under "Editor appearance" > "Plugins", check the "CKEditor Link" box.
Save changes.
*When using the Wysiwyg module*
Go to admin/config/content/wysiwyg and edit the desired CKEditor-enabled input
format.
Under "Buttons and plugins", check both "Link" and "CKEditor Link" boxes.
Save changes.
*Set up CKEditor Link Filter*
Go to admin/config/content/formats and edit the desired text format.
Check the "CKEditor Link Filter" box.
If you use other path converting filters like Pathologic or Path Filter, make
sure that CKEditor Link Filter comes before them:
Under "Filter processing order", drag and drop CKEditor Link Filter before
these filters in the list.
Save changes.
*Configure CKEditor Link*
Go to admin/config/content/ckeditor_link.
Change settings as desired.
Save changes.
EXTENDING CKEDITOR LINK
Developers, see the ckeditor_link.api.php file.
......
......@@ -2,3 +2,4 @@ name = CKEditor Link
description = Easily create links to Drupal internal paths through CKEditor.
package = User interface
core = 7.x
configure = admin/config/content/ckeditor_link
......@@ -147,15 +147,13 @@ function ckeditor_link_ckeditor_link_types() {
if (module_exists('taxonomy')) {
$types[] = array('type' => 'taxonomy', 'file' => 'includes/ckeditor_link.taxonomy.inc');
// TODO: Add support for pgsql.
if (in_array(db_driver(), array('mysql')) && module_exists('i18n_taxonomy')) {
if (module_exists('i18n_taxonomy')) {
$types[] = array('type' => 'i18n_taxonomy', 'file' => 'includes/ckeditor_link.i18n_taxonomy.inc');
}
}
$types[] = array('type' => 'menu', 'file' => 'includes/ckeditor_link.menu.inc');
// TODO: Add support for pgsql.
if (in_array(db_driver(), array('mysql')) && module_exists('i18n_menu')) {
if (module_exists('i18n_menu')) {
$types[] = array('type' => 'i18n_menu', 'file' => 'includes/ckeditor_link.i18n_menu.inc');
}
......
......@@ -9,6 +9,12 @@
* Implementation of hook_ckeditor_link_TYPE_autocomplete().
*/
function ckeditor_link_ckeditor_link_i18n_menu_autocomplete($string) {
// Currently, this function only supports MySQL.
// TODO: Add support for pgsql.
if (!in_array(db_driver(), array('mysql'))) {
return array();
}
$matches = array();
$menus = array_keys(array_filter(variable_get('ckeditor_link_autocomplete_menus', array())));
......@@ -39,3 +45,32 @@ function ckeditor_link_ckeditor_link_i18n_menu_autocomplete($string) {
return $matches;
}
/**
* Implementation of hook_ckeditor_link_TYPE_revert().
*/
function ckeditor_link_ckeditor_link_i18n_menu_revert($path, &$langcode) {
$router_item = menu_get_item($path);
if ($router_item && $router_item['access']) {
$result = db_query('SELECT mlid, link_title, language FROM {menu_links} WHERE link_path = :link_path AND hidden = 0 ORDER BY customized DESC', array(':link_path' => $path));
$default_langcode = language_default('language');
$link_title = NULL;
foreach ($result as $item) {
if ($item->language == $langcode) {
$link_title = $item->link_title;
break;
}
elseif (($item->language == $default_langcode) && ($langcode == LANGUAGE_NONE)) {
$langcode = $default_langcode;
$link_title = $item->link_title;
break;
}
elseif (!$link_title && ($item->language == LANGUAGE_NONE)) {
$link_title = i18n_string_translate(array('menu', 'item', $item->mlid, 'title'), $item->link_title, array('langcode' => $langcode));
}
}
return ($link_title) ? $link_title : NULL;
}
return FALSE;
}
......@@ -9,6 +9,12 @@
* Implementation of hook_ckeditor_link_TYPE_autocomplete().
*/
function ckeditor_link_ckeditor_link_i18n_taxonomy_autocomplete($string) {
// Currently, this function only supports MySQL.
// TODO: Add support for pgsql.
if (!in_array(db_driver(), array('mysql'))) {
return array();
}
$matches = array();
$vocabularies = array_keys(array_filter(variable_get('ckeditor_link_autocomplete_vocabularies', array())));
......
......@@ -13,18 +13,18 @@ function ckeditor_link_ckeditor_link_menu_autocomplete($string) {
$menus = array_keys(array_filter(variable_get('ckeditor_link_autocomplete_menus', array())));
if (count($menus)) {
$query = db_select('menu_links', 'ml')
->fields('ml', array('link_path', 'link_title'))
->condition('ml.link_title', '%'. db_like($string) .'%', 'LIKE')
->condition('ml.hidden', 0)
->condition('ml.external', 0)
->orderBy('ml.link_title')
$query = db_select('menu_links')
->fields('menu_links', array('link_path', 'link_title'))
->condition('link_title', '%'. db_like($string) .'%', 'LIKE')
->condition('hidden', 0)
->condition('external', 0)
->orderBy('link_title')
->range(0, 10);
if (function_exists('ckeditor_link_ckeditor_link_i18n_menu_autocomplete')) {
$query->fields('ml', array('language'));
$query->fields('menu_links', array('language'));
}
if (!in_array('- any -', $menus)) {
$query->condition('ml.menu_name', $menus, 'IN');
$query->condition('menu_name', $menus, 'IN');
}
$result = $query->execute();
foreach ($result as $item) {
......@@ -40,6 +40,23 @@ function ckeditor_link_ckeditor_link_menu_autocomplete($string) {
return $matches;
}
/**
* Implementation of hook_ckeditor_link_TYPE_revert().
*/
function ckeditor_link_ckeditor_link_menu_revert($path, &$langcode) {
if (function_exists('ckeditor_link_ckeditor_link_i18n_menu_revert')) {
return;
}
$router_item = menu_get_item($path);
if ($router_item && $router_item['access']) {
$link_title = db_query("SELECT link_title FROM {menu_links} WHERE link_path = :link_path AND hidden = 0 ORDER BY customized DESC", array(':link_path' => $path))->fetchField();
return ($link_title) ? $link_title : NULL;
}
return FALSE;
}
/**
* Implementation of hook_ckeditor_link_TYPE_settings().
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment