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

First commit to Drupal 7 branch

parent c26047dd
......@@ -2,4 +2,6 @@
name = CKEditor Link
description = Easily create links to Drupal internal paths through CKEditor.
package = User interface
core = 6.x
\ No newline at end of file
core = 7.x
files[] = ckeditor_link.module
files[] = ckeditor_link.install
......@@ -5,5 +5,8 @@
* Implementation of hook_install().
*/
function ckeditor_link_install() {
db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", 1, 'ckeditor_link');
db_update('system')
->fields(array('weight' => 1))
->condition('name', 'ckeditor_link')
->execute();
}
......@@ -13,15 +13,15 @@
function ckeditor_link_init() {
if (!variable_get('clean_url', 0)) {
module_disable(array('ckeditor_link'));
drupal_set_message(t('<em>CKEditor Link</em> has been disabled. <a href="!url">Clean URLs</a> need to be enabled for this module to work properly.', array('!url' => url('admin/settings/clean-urls'))), 'warning');
drupal_set_message(t('<em>CKEditor Link</em> has been disabled. <a href="!url">Clean URLs</a> need to be enabled for this module to work properly.', array('!url' => url('admin/config/search/clean-urls'))), 'warning');
}
}
/**
* Implementation of hook_perm().
* Implementation of hook_permission().
*/
function ckeditor_link_perm() {
return array('access ckeditor link');
function ckeditor_link_permission() {
return array('access ckeditor link' => array('title' => t('Access <em>CKEditor Link</em>')));
}
/**
......@@ -40,14 +40,20 @@ function ckeditor_link_autocomplete($string = '') {
$matches = array();
if ($string !== '') {
$sql = db_rewrite_sql("SELECT n.nid, n.title FROM {node} n WHERE n.title LIKE '%%%s%%' ORDER BY n.title, n.type");
$result = db_query_range($sql, array($string), 0, 10);
while ($node = db_fetch_object($result)) {
$query = db_select('node', 'n')
->fields('n', array('nid', 'title'))
->condition('n.title', '%'. $string .'%', 'LIKE')
->orderBy('n.title')
->orderBy('n.type')
->range(0, 10)
->addTag('node_access');
$result = $query->execute();
foreach ($result as $node) {
$matches[$node->title .' (node/'. $node->nid. ')'] = '<div class="reference-autocomplete">'. check_plain($node->title) .'</div>';
}
}
drupal_json($matches);
drupal_json_output($matches);
}
/**
......@@ -61,13 +67,13 @@ function ckeditor_link_form_alter(&$form, &$form_state) {
function ckeditor_link_process_form(&$form, &$form_state) {
static $added = FALSE;
if (!$added && ($js = drupal_add_js()) && isset($js['setting'])) {
$setting = call_user_func_array('array_merge_recursive', $js['setting']);
if (isset($setting['ckeditor']) || isset($setting['wysiwyg']['configs']['ckeditor'])) {
drupal_add_css(drupal_get_path('module', 'ckeditor_link').'/ckeditor_link.css');
if (!$added && ($js = drupal_add_js()) && isset($js['settings']['data'])) {
$settings = call_user_func_array('array_merge_recursive', $js['settings']['data']);
if (isset($settings['ckeditor']) || isset($settings['wysiwyg']['configs']['ckeditor'])) {
drupal_add_css(drupal_get_path('module', 'ckeditor_link') .'/ckeditor_link.css');
drupal_add_js('misc/autocomplete.js');
drupal_add_js(array('ckeditor_link' => array(
'module_path' => base_path().drupal_get_path('module', 'ckeditor_link'),
'module_path' => base_path() . drupal_get_path('module', 'ckeditor_link'),
'autocomplete_path' => url('ckeditor_link/autocomplete'),
'msg_invalid_path' => t('Link must be a valid Drupal path.'),
)), 'setting');
......@@ -83,7 +89,7 @@ function ckeditor_link_process_form(&$form, &$form_state) {
function ckeditor_link_wysiwyg_plugin($editor, $version) {
if (($editor == 'ckeditor') && user_access('access ckeditor link')) {
return array('drupal_path' => array(
'path' => drupal_get_path('module', 'ckeditor_link').'/plugins/link/',
'path' => drupal_get_path('module', 'ckeditor_link') .'/plugins/link/',
'load' => TRUE,
'extensions' => array('Link' => t('CKEditor Link')),
));
......@@ -91,35 +97,27 @@ function ckeditor_link_wysiwyg_plugin($editor, $version) {
}
/**
* Implementation of hook_filter().
* Implementation of hook_filter_info().
*/
function ckeditor_link_filter($op, $delta = 0, $format = -1, $text = '', $cache_id = 0) {
switch ($op) {
case 'list':
return array(0 => t('CKEditor Link Filter'));
case 'description':
return t('Converts links added through <em>CKEditor Link</em> into aliased and language prefixed URLs.');
case 'no cache':
return FALSE;
case 'prepare':
return $text;
case 'process':
return preg_replace_callback('`\bhref="'. preg_quote(base_path(), '`') .'node/(\d+)(?=[?#"])`', '_ckeditor_link_filter_process', $text);
function ckeditor_link_filter_info() {
$filters['ckeditor_link_filter'] = array(
'title' => t('CKEditor Link Filter'),
'description' => t('Converts links added through <em>CKEditor Link</em> into aliased and language prefixed URLs.'),
'process callback' => 'ckeditor_link_filter_process',
);
return $filters;
}
default:
return $text;
}
function ckeditor_link_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) {
return preg_replace_callback('`\bhref="'. preg_quote(base_path(), '`') .'node/(\d+)(?=[?#"])`', '_ckeditor_link_filter_process', $text);
}
function _ckeditor_link_filter_process($matches) {
$nid = $matches[1];
$options = array();
if ($lang = db_result(db_query('SELECT language FROM {node} WHERE nid = %d', $nid))) {
$lang = db_query('SELECT language FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchField();
if ($lang && ($lang != LANGUAGE_NONE)) {
$languages = language_list('enabled');
$languages = $languages[1];
if (isset($languages[$lang])) {
......
......@@ -10,7 +10,7 @@
* For licensing, see LICENSE.html or http://ckeditor.com/license
*/
(function() {
(function($) {
// Get a CKEDITOR.dialog.contentDefinition object by its ID.
var getById = function(array, id, recurse) {
......@@ -26,7 +26,7 @@
var initAutocomplete = function(input, uri) {
input.setAttribute('autocomplete', 'OFF');
new Drupal.jsAC(input, new Drupal.ACDB(uri));
new Drupal.jsAC($(input), new Drupal.ACDB(uri));
};
var extractPath = function(value) {
......@@ -147,4 +147,4 @@
});
}
});
})();
\ No newline at end of file
})(jQuery);
\ No newline at end of file
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