Commit dca91b50 authored by anon's avatar anon

Initial Release for Drupal 6

parents
body#linkit {
padding:1em;
background-image:none;
background-color:#f0f0ee;
}
#linkit .form-item {
float:left;
margin-right:1em;
}
#linkit .form-text {
border:1px solid #ccc;
padding:5px;
-moz-border-radius:5px;
}
#linkit .form-submit {
margin: 2.8em 0 1em 0;
float:left;
clear:right;
}
#linkit input.form-autocomplete {
border:1px solid #ccc;
padding:5px;
background-position:100% 5px;
-moz-border-radius:5px;
}
#linkit input.throbbing {
background-position:100% -15px;
}
.auto-item-type {
float:right;
font-weight:bold;
font-size:10px;
}
.auto-item-title {
margin-right:1.5em;
float:left;
}
\ No newline at end of file
<?php
// $Id$
/**
* @file
* Wysiwyg API integration.
*/
/**
* Implementation of hook_wysiwyg_plugin().
*/
function linkit_linkit_plugin() {
$plugins['linkit_tinymce'] = array(
'title' => t('Linkit (TinyMCE)'),
'vendor url' => 'http://drupal.org/project/linkit',
'icon file' => 'linkit.png',
'icon title' => t('Insert a link with the linkitmodule.'),
'settings' => array(
'dialog' => array(
'title' => t('Test'),
'url' => url('admin/linkit/dashboard'),
'width' => 640,
'height' => 480,
),
),
);
return $plugins;
}
\ No newline at end of file
// $Id$
tinyMCE.addToLang('tinymce', {
title: 'title',
foo: 'foo',
bar: 'bar'
});
\ No newline at end of file
.mceButtonDisabled img { opacity:0.3; }
\ No newline at end of file
// $Id$
Drupal.wysiwyg.plugins["linkit_tinymce"] = {
/**
* Execute the button.
*/
invoke: function(data, settings, instanceId) {
// Options to pass to the dialog.
var options = { id: instanceId, content: data.content };
// Open dialogue.
Drupal.wysiwyg.instances[instanceId].openDialog(settings.dialog, options);
},
attach: function(content, settings, instanceId) {
$('#edit-body_linkit_tinymce').removeClass('mceButtonEnabled').addClass('mceButtonDisabled');
function addEvents(win) {
if (win.contentWindow) {
win = win.contentWindow;
}
$(win.document).bind("mouseup", function() {
var selection = this.getSelection();
if(selection == "") {
$('#edit-body_linkit_tinymce').removeClass('mceButtonEnabled').addClass('mceButtonDisabled');
} else {
$('#edit-body_linkit_tinymce').removeClass('mceButtonDisabled').addClass('mceButtonEnabled');
}
});
}
var frames = document.getElementsByTagName("iframe");
for (var i=0; i < frames.length; i++) {
addEvents(frames[i]);
}
return content;
}
};
\ No newline at end of file
// $Id$
Drupal.linkit = Drupal.linkit || {};
Drupal.linkit.plugins = Drupal.linkit.plugins || {};
Drupal.behaviors.linkit_tinymce_dialog = function (context) {
var parentWindow = (window.opener) ? window.opener : window.parent;
if (parentWindow && parentWindow.Drupal) {
var instanceId = parentWindow.Drupal.wysiwyg.activeId;
var content = parentWindow.tinyMCE.activeEditor.selection.getContent();
var selection = parentWindow.tinyMCE.activeEditor.selection;
var basePath = parentWindow.Drupal.settings.basePath;
var href;
var link;
$('#edit-insert-internal').click(function() {
// What type is the link?
var type = $('#edit-internal', context).val().match(/\[type:([a-z0-9 \_\/]*)\]/i);
type = type[1].toLowerCase();
// Do we have the plugin?
if(typeof Drupal.linkit.plugins[type] == 'undefined') {
alert('Cant find the "Drupal.linkit.plugins['+type+'].invoke" function');
return false;
}
// Okey, we have it
else {
var href = Drupal.linkit.plugins[type].invoke($('#edit-internal', context).val(), basePath);
}
link = "<a href=\""+ href +"\">"+ content +"</a>";
setLink();
return false;
});
$('#edit-insert-external').click(function() {
href = $('#edit-external', context).val();
link = "<a href=\""+ href +"\">"+ content +"</a>";
setLink();
return false;
});
}
function setLink() {
// If the selection an <a>, do an update instead of insert
if(parentWindow.tinyMCE.activeEditor.dom.getParent(selection.getNode(), 'A')) {
parentWindow.tinyMCE.activeEditor.execCommand('mceInsertLink', false, href);
}
else {
parentWindow.Drupal.wysiwyg.instances[instanceId].insert(link);
}
// Close the popup window
parentWindow.Drupal.wysiwyg.instances[instanceId].closeDialog(window);
}
};
/**
* Default plugins
*/
Drupal.linkit.plugins['node'] = {
invoke: function(str) {
var matches = str.match(/\[nid:(\d+)\]/i);
return 'internal:node/'+matches[1];
}
};
Drupal.linkit.plugins['view'] = {
invoke: function(str, basePath) {
var matches = str.match(/\[path:(.*)\]/i);
return basePath + matches[1];
}
};
\ No newline at end of file
<?php
// $Id$
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language ?>" lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Linkit</title>
<?php print $head; ?>
<?php print $styles; ?>
<?php print $scripts; ?>
</head>
<body id="linkit">
<?php if (!empty($messages)): print $messages; endif; ?>
<?php if (!empty($help)): print $help; endif; ?>
<div class="clear-block">
<h1><?php print t('What kind of link do you what to insert?'); ?></h1>
<?php print $content; ?>
</div>
<?php print $closure; ?>
</body>
</html>
\ No newline at end of file
; $Id$
name = Linkit
description = Linkit desc...
core = 6.x
dependencies[] = "wysiwyg"
dependencies[] = "pathfilter"
\ No newline at end of file
<?php
// $Id$
/**
* @file
*
*/
/**
* Implementation of hook_wysiwyg_include_directory().
*
* @param string $type
* Contains either "plugins" or "editors"?
* @return string
* The function returns the include directory "plugins". This directory must only
* contain wysiwyg api integration files.
*/
function linkit_wysiwyg_include_directory($type) {
switch ($type) {
case 'plugins':
return 'editors';
}
}
/**
* Implementation of hook_menu().
*/
function linkit_menu() {
$items = array();
$items['admin/linkit/dashboard/%'] = array(
'title' => 'Linkit',
'description' => 'Dashboard',
'page callback' => 'linkit_dashboard',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['admin/linkit/autocomplete'] = array(
'title' => 'Link to node',
'description' => 'description',
'page callback' => 'linkit_autocomplete',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'page arguments' => array(3,4),
);
return $items;
}
/**
* Implementation of hook_theme().
*/
function linkit_theme($existing, $type, $theme, $path) {
return array(
'linkit_dashboard' => array(
'arguments' => array('content' => NULL),
'template' => 'linkit-dashboard',
),
);
}
/**
* Template preprocess function for theme_linkit_dashboard().
*/
function template_preprocess_linkit_dashboard(&$variables) {
// Construct page title
$head_title = array(strip_tags(drupal_get_title()), variable_get('site_name', 'Drupal'));
$variables['head_title'] = implode(' | ', $head_title);
$variables['base_path'] = base_path();
$variables['front_page'] = url();
$variables['head'] = drupal_get_html_head();
$variables['help'] = theme('help');
$variables['language'] = $GLOBALS['language'];
$variables['language']->dir = $GLOBALS['language']->direction ? 'rtl' : 'ltr';
$variables['messages'] = $variables['show_messages'] ? theme('status_messages') : '';
$variables['css'] = drupal_add_css();
$variables['styles'] = drupal_get_css();
$variables['scripts'] = drupal_get_js();
$variables['title'] = drupal_get_title();
$variables['closure'] = theme('closure');
}
/**
*
*/
function linkit_dashboard() {
module_invoke('admin_menu', 'suppress');
// Add CSS.
drupal_add_css(drupal_get_path('module', 'linkit') . '/css/linkit.css');
// Add JavaScript.
drupal_add_js(drupal_get_path('module', 'linkit') . '/editors/linkit_tinymce/linkit_tinymce_dialog.js');
$plugins = module_invoke_all('linkit_info_plugins');
foreach ($plugins as $name => $properties) {
$plugin = &$plugins[$name];
// Fill in required/default properties.
$plugin += array(
'type' => $name,
'js file' => $name . '.js',
);
$fileurl = drupal_get_path('module', $name).'/'.$plugin['js file'];
// Check whether the js-file is present.
if (file_exists($fileurl)) {
drupal_add_js($fileurl);
}
}
echo theme('linkit_dashboard', drupal_get_form('_linkit_form'));
exit();
}
/**
* Autocomplete callback function
*/
function linkit_autocomplete($string = NULL) {
$matches = array();
if($string) {
$hook_matches = module_invoke_all('linkit_load_plugins', $string);
if(count($hook_matches) > 0) {
$matches = $hook_matches;
}
}
drupal_json($matches);
}
/**
* Creates the
*/
function _linkit_autolist_list($title = NULL, $type = NULL) {
$output = '<div class="auto-item-title">'.check_plain($title).'</div>';
$output .= '<div class="auto-item-type">[type:'.check_plain($type).']</div>';
return '<div class="clear-block">'.$output.'</div>';
}
/**
* Autocomplete callback function
*/
function _linkit_autolist_val($title = NULL, $type = NULL, $info = NULL) {
return check_plain($title.' [type:'.$type.'] ['.$info.']');
}
/**
*
*/
function _linkit_form() {
$form['internal'] = array(
'#type' => 'textfield',
'#title' => t('Internal'),
'#description' => t('Search for the title/path'),
'#maxlength' => 255,
'#size' => 80,
'#autocomplete_path' => 'admin/linkit/autocomplete',
'#default_value' => '',
'#weight' => 1,
);
$form['insert-internal'] = array(
'#type' => 'button',
'#value' => t('Insert'),
'#weight' => 2,
);
$form['external'] = array(
'#type' => 'textfield',
'#title' => t('External'),
'#description' => t('Type the URL (http://www.example.com)'),
'#maxlength' => 255,
'#size' => 80,
'#default_value' => '',
'#weight' => 3,
);
$form['insert-external'] = array(
'#type' => 'button',
'#value' => t('Insert'),
'#weight' => 4,
);
return $form;
}
/**
* Implementation of hook_linkit_load_plugins().
*/
function linkit_linkit_load_plugins($string) {
$matches = array();
// Get nodes
$result = db_query_range("SELECT title, nid FROM {node} WHERE LOWER(title) LIKE LOWER('%s%%')", $string, 0, 10);
while ($node = db_fetch_object($result)) {
$matches[_linkit_autolist_val($node->title, 'Node', 'nid:'.$node->nid)] = _linkit_autolist_list($node->title, 'Node');
}
// Get all page displays in view
// Create temporary table
$temp_table = 'CREATE TEMPORARY TABLE {linkit_tmp_view_table} (title VARCHAR(128) NOT NULL, path VARCHAR(128) NOT NULL)';
db_query($temp_table);
// Get all displays that are "page" and their path
$result = db_query("SELECT w.name, wd.display_options FROM {views_view} AS w INNER JOIN {views_display} AS wd ON w.vid = wd.vid WHERE wd.display_plugin = '%s'", 'page');
while ($node = db_fetch_object($result)) {
$optinos = unserialize($node->display_options);
db_query("INSERT INTO {linkit_tmp_view_table} (title, path) VALUES ('%s', '%s')", $node->name, $optinos['path']);
}
$result = db_query_range("SELECT * FROM {linkit_tmp_view_table} WHERE LOWER(path) LIKE LOWER('%s%%')", $string, 0, 10);
while ($node = db_fetch_object($result)) {
$matches[_linkit_autolist_val($node->path, 'View', 'path:'.$node->path)] = _linkit_autolist_list($node->path, 'View');
}
return $matches;
}
\ No newline at end of file
Markdown is supported
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