summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Stjerneman2010-02-19 23:54:33 +0000
committerEmil Stjerneman2010-02-19 23:54:33 +0000
commitdca91b5015efa126a5c68089af80258d761b968e (patch)
tree50c86b6d8a66812ae9ad6fb08fcdd69bcffcd7a4
Initial Release for Drupal 66.x-1.0-alpha1
-rw-r--r--css/linkit.css44
-rw-r--r--editors/linkit.inc28
-rw-r--r--editors/linkit_tinymce/images/linkit.pngbin0 -> 608 bytes
-rw-r--r--editors/linkit_tinymce/langs/en.js7
-rw-r--r--editors/linkit_tinymce/linkit_tinymce.css1
-rw-r--r--editors/linkit_tinymce/linkit_tinymce.js40
-rw-r--r--editors/linkit_tinymce/linkit_tinymce_dialog.js76
-rw-r--r--linkit-dashboard.tpl.php23
-rw-r--r--linkit.info6
-rw-r--r--linkit.module210
10 files changed, 435 insertions, 0 deletions
diff --git a/css/linkit.css b/css/linkit.css
new file mode 100644
index 0000000..265fb4c
--- /dev/null
+++ b/css/linkit.css
@@ -0,0 +1,44 @@
+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
diff --git a/editors/linkit.inc b/editors/linkit.inc
new file mode 100644
index 0000000..47b18c2
--- /dev/null
+++ b/editors/linkit.inc
@@ -0,0 +1,28 @@
+<?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
diff --git a/editors/linkit_tinymce/images/linkit.png b/editors/linkit_tinymce/images/linkit.png
new file mode 100644
index 0000000..dd25023
--- /dev/null
+++ b/editors/linkit_tinymce/images/linkit.png
Binary files differ
diff --git a/editors/linkit_tinymce/langs/en.js b/editors/linkit_tinymce/langs/en.js
new file mode 100644
index 0000000..808a3d7
--- /dev/null
+++ b/editors/linkit_tinymce/langs/en.js
@@ -0,0 +1,7 @@
+// $Id$
+
+tinyMCE.addToLang('tinymce', {
+ title: 'title',
+ foo: 'foo',
+ bar: 'bar'
+}); \ No newline at end of file
diff --git a/editors/linkit_tinymce/linkit_tinymce.css b/editors/linkit_tinymce/linkit_tinymce.css
new file mode 100644
index 0000000..7c43821
--- /dev/null
+++ b/editors/linkit_tinymce/linkit_tinymce.css
@@ -0,0 +1 @@
+.mceButtonDisabled img { opacity:0.3; } \ No newline at end of file
diff --git a/editors/linkit_tinymce/linkit_tinymce.js b/editors/linkit_tinymce/linkit_tinymce.js
new file mode 100644
index 0000000..0260ce3
--- /dev/null
+++ b/editors/linkit_tinymce/linkit_tinymce.js
@@ -0,0 +1,40 @@
+// $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
diff --git a/editors/linkit_tinymce/linkit_tinymce_dialog.js b/editors/linkit_tinymce/linkit_tinymce_dialog.js
new file mode 100644
index 0000000..5b06590
--- /dev/null
+++ b/editors/linkit_tinymce/linkit_tinymce_dialog.js
@@ -0,0 +1,76 @@
+// $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
diff --git a/linkit-dashboard.tpl.php b/linkit-dashboard.tpl.php
new file mode 100644
index 0000000..43fc080
--- /dev/null
+++ b/linkit-dashboard.tpl.php
@@ -0,0 +1,23 @@
+<?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
diff --git a/linkit.info b/linkit.info
new file mode 100644
index 0000000..6804161
--- /dev/null
+++ b/linkit.info
@@ -0,0 +1,6 @@
+; $Id$
+name = Linkit
+description = Linkit desc...
+core = 6.x
+dependencies[] = "wysiwyg"
+dependencies[] = "pathfilter" \ No newline at end of file
diff --git a/linkit.module b/linkit.module
new file mode 100644
index 0000000..2b7e37b
--- /dev/null
+++ b/linkit.module
@@ -0,0 +1,210 @@
+<?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