Index: img_assist.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/img_assist.info,v retrieving revision 1.5 diff -u -p -r1.5 img_assist.info --- img_assist.info 18 Jul 2008 22:58:09 -0000 1.5 +++ img_assist.info 12 Aug 2009 06:24:38 -0000 @@ -2,6 +2,7 @@ name = Image assist description = This module allows users to upload and insert inline images into posts. It automatically generates an Add image link under the textarea fields of your choice. dependencies[] = image +dependencies[] = inline dependencies[] = views package = Image core = 6.x Index: img_assist.inline.inc =================================================================== RCS file: img_assist.inline.inc diff -N img_assist.inline.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ img_assist.inline.inc 12 Aug 2009 07:12:07 -0000 @@ -0,0 +1,83 @@ + array( + '#title' => t('Node id'), + '#description' => t('A node id containing an image file to render.'), + '#type' => 'int', + ), + 'fid' => array( + '#title' => t('File id'), + '#description' => t('A file id of an image file to render.'), + '#type' => 'int', + ), + ); + return $args; + + case 'presave': + // Context may be passed via inline_nodeapi(); update our mapping table. + if (isset($macro->params['nid']) && !empty($macro->context['node'])) { + static $shutdown_added; + if (!isset($shutdown_added)) { + register_shutdown_function('img_assist_inline_map_update'); + $shutdown_added = TRUE; + } + img_assist_inline_map_update($macro->context['node']->nid, $macro->params['nid']); + } + return; + + case 'validate': + if (!isset($macro->params['nid']) && !isset($macro->params['fid'])) { + return FALSE; + } + return TRUE; + + case 'render': + $output = img_assist_render_image($macro->params); + return $output; + } +} + +/** + * @todo This was only invoked when at least 1 macro was processed, but only + * appended once to the entire filtered text (not each macro). + */ +function theme_img_assist_filter($text) { + // The div tag added to the end of each node is necessary to clear the + // floating properties of inline images immediately after a node's content. + return $text . '
'; +} + +/** + * Update img_assist_map image reference table. + */ +function img_assist_inline_map_update($nid, $iid) { + static $updates = array(); + + if (isset($nid) && isset($iid)) { + $updates[$nid][] = $iid; + } + // Final shutdown. + else { + foreach ($updates as $nid => $iids) { + db_query('DELETE FROM {img_assist_map} WHERE nid = %d', $nid); + $iids = array_unique($iids); + foreach ($iids as $iid) { + db_query('INSERT INTO {img_assist_map} (nid, iid) VALUES (%d, %d)', $nid, $iid); + } + } + } +} + Index: img_assist.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/img_assist.module,v retrieving revision 1.107 diff -u -p -r1.107 img_assist.module --- img_assist.module 13 Aug 2009 19:32:44 -0000 1.107 +++ img_assist.module 13 Aug 2009 19:33:15 -0000 @@ -33,6 +33,7 @@ function img_assist_theme() { ), 'img_assist_filter' => array( 'arguments' => array('text' => NULL), + 'file' => 'img_assist.inline.inc', ), 'img_assist_popup' => array( 'arguments' => array('content' => NULL, 'attributes' => NULL), @@ -96,7 +97,6 @@ function img_assist_menu() { ); // Insert callback (only for inserting HTML, not filter tag). $items['img_assist/insert_html'] = array( - 'title' => 'Insert callback', 'page callback' => 'img_assist_insert_html', 'access arguments' => array('access img_assist'), 'type' => MENU_CALLBACK, @@ -159,7 +159,7 @@ function img_assist_textarea($element) { } $link = variable_get('img_assist_link', 'icon'); if ($link == 'icon' || $link == 'text') { - if (_img_assist_textarea_match($element['#id']) && _img_assist_page_match() && !strstr($_GET['q'], 'img_assist')) { + if (!strstr($_GET['q'], 'img_assist')) { if (!$initialized) { // Add settings. $settings['link'] = $link; @@ -197,11 +197,9 @@ function img_assist_block($op = 'list', else if ($op == 'view') { switch ($delta) { case 0: - // Since blocks aren't passed node objects (which makes sense) we need - // to determine if we are viewing a node and grab its nid. - if (arg(0) == 'node' && is_numeric(arg(1))) { + if ($node = menu_get_object()) { $block['subject'] = t('This image appears in...'); - $block['content'] = img_assist_get_references(arg(1)); + $block['content'] = img_assist_get_references($node->nid); return $block; } break; @@ -210,61 +208,21 @@ function img_assist_block($op = 'list', } /** - * Implementation of hook_filter(). + * Implementation of hook_inline_info(). */ -function img_assist_filter($op, $delta = 0, $format = -1, $text = '') { - switch ($op) { - case 'list': - return array(0 => t('Inline images')); - - case 'description': - return t('Add images to your posts with Image assist.'); - -// case 'no cache': -// return TRUE; - - case 'process': - $processed = FALSE; - foreach (img_assist_get_macros($text) as $unexpanded_macro => $macro) { - $expanded_macro = img_assist_render_image($macro); - $text = str_replace($unexpanded_macro, $expanded_macro, $text); - $processed = TRUE; - } - return $processed ? theme('img_assist_filter', $text) : $text; - - default: - return $text; - } -} - -/** - * Implementation of hook_filter_tips(). - */ -function img_assist_filter_tips($delta, $format, $long = FALSE) { - return t('Images can be added to this post.'); +function img_assist_inline_info() { + $info['img_assist'] = array( + 'file' => 'img_assist.inline.inc', + 'callback' => 'img_assist_inline', + ); + return $info; } /** * Implementation of hook_nodeapi(). - * - * - Clear input filter cache. - * - Keep track of where images are used. - * - Catch nids of recently uploaded images. */ function img_assist_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { switch ($op) { - case 'update': - if ($node->type == 'image') { - // Clear the input filter cache to force all node content to be rebuilt. - // This is to make sure all image paths are up to date. - cache_clear_all(NULL, 'cache_filter'); - } - // break is intentionally left out. - case 'insert': - // Update the image map. - img_assist_map_save($node); - break; - case 'delete': img_assist_map_delete($node); break; @@ -1285,45 +1243,6 @@ function img_assist_popup() { */ /** - * Update the map table - * - * Look for any images linked in this content and keep a reference of them. - */ -function img_assist_map_save($node) { - $content = $node->body; - // If CCK is used, image macros can be found in fields other than the body. - // Get all the fields that use text filtering and extract their content: - if (function_exists('content_types')) { - $type = content_types($node->type); - if (!empty($type['fields'])) { - foreach ($type['fields'] as $field) { - // Distinguish between plain text fields and filtered fields: - if (!empty($field['text_processing'])) { - if (count($node->{$field['field_name']})) { - foreach ($node->{$field['field_name']} as $field_instance) { - $content .= $field_instance['value']; - } - } - } - } - } - } - - // Get all the macros from the content: - $macros = (array)img_assist_get_macros($content); - - // Save the image references: - db_query('DELETE FROM {img_assist_map} WHERE nid = %d', $node->nid); - $nids = array(); - foreach ($macros as $m) { - if (!isset($nids[$m['nid']]) && is_numeric($m['nid'])) { - db_query('INSERT INTO {img_assist_map} (nid, iid) VALUES(%d, %d)', $node->nid, $m['nid']); - $nids[$m['nid']] = $m['nid']; - } - } -} - -/** * Delete references to a non-existant node. * * If a node is being deleted update the map table. The node can either be an @@ -1335,30 +1254,17 @@ function img_assist_map_delete($node) { } /** - * Load the image map for a given nid. - */ -function img_assist_map_load($nid) { - $imagemap = array(); - $result = db_query('SELECT * FROM {image} i INNER JOIN {img_assist_map} iam ON i.nid = iam.iid WHERE i.nid = %d', $nid); - while ($data = db_fetch_object($result)) { - $imagemap[] = $data->nid; - } - - return $imagemap; -} - -/** * Return a list of node links for a given nid. */ function img_assist_get_references($nid, $limit = 10) { $and_clause = array(); - $images = img_assist_map_load($nid); - foreach ($images as $id) { - $and_clause[] = 'n.nid = '. $id; + $images = array(); + $result = db_query('SELECT * FROM {image} i INNER JOIN {img_assist_map} iam ON i.nid = iam.iid WHERE i.nid = %d', $nid); + while ($data = db_fetch_object($result)) { + $and_clause[] = 'n.nid = ' . $data->nid; } - $and_clause = implode(' OR ', $and_clause); - - if ($images) { + if ($and_clause) { + $and_clause = implode(' OR ', $and_clause); return node_title_list(db_query_range(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n WHERE n.status = 1 AND $and_clause ORDER BY n.nid DESC"), 0, (int) $limit)); } } @@ -1368,94 +1274,6 @@ function img_assist_get_references($nid, */ /** - * @defgroup img_assist_macro Image Assist Filter macro parsing - * @{ - */ - -/** - * Return all img_assist macros as an array. - */ -function img_assist_get_macros($text) { - $m = array(); - preg_match_all('/ \[ ( [^\[\]]+ )* \] /x', $text, $matches); - // Don't process duplicates. - $tag_match = (array) array_unique($matches[1]); - - foreach ($tag_match as $macro) { - $current_macro = '['. $macro .']'; - $param = array_map('trim', explode('|', $macro)); - // The first macro param is assumed to be the function name. - $func_name = array_shift($param); - if ($func_name == 'img_assist') { - $vars = array(); - foreach ($param as $p) { - $pos = strpos($p, '='); - $varname = trim(substr($p, 0, $pos)); - $varvalue = substr($p, $pos + 1); - $vars[$varname] = trim($varvalue); - } - // The full unaltered filter string is the key for the array of filter - // attributes. - $m[$current_macro] = $vars; - } - } - - return $m; -} - -/** - * Determine if img_assist can render the current page. - * @see block_list(). - * - * @return - * TRUE if can render, FALSE if not allowed. - */ -function _img_assist_page_match() { - $must_match = variable_get('img_assist_paths_type', 2); - if ($must_match == 2) { - return TRUE; - } - else { - $paths = variable_get('img_assist_paths', "node/*\ncomment/*"); - $path = drupal_get_path_alias($_GET['q']); - $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'), preg_quote($paths, '/')) .')$/'; - $match = preg_match($regexp, $path); - return $match != $must_match; - } -} - -/** - * Determine if img_assist can render the current textarea. - * @see block_list(). - * - * @return - * TRUE if can render, FALSE if not allowed. - */ -function _img_assist_textarea_match($formid) { - $must_match = variable_get('img_assist_textareas_type', 2); - if ($must_match == 2) { - return TRUE; - } - else { - $formids = variable_get('img_assist_textareas', "edit-body\nedit-comment"); - - $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/'), array('|', '.*'), preg_quote($formids, '/')) .')$/'; - // Compare with the form id. - $page_match = preg_match($regexp, $formid); - // When $must_match has a value of 0, img_assist is displayed on - // all pages except those listed in img_assist_textareas. When set to 1, it - // is displayed only on those textareas listed in img_assist_textareas. - $page_match = !($must_match xor $page_match); - - return $page_match; - } -} - -/** - * @} End of "defgroup img_assist_macro". - */ - -/** * @defgroup img_assist_theme Image Assist Theme functions * @{ * @@ -1525,12 +1343,6 @@ function theme_img_assist_inline($node, return $output; } -function theme_img_assist_filter($text) { - // The div tag added to the end of each node is necessary to clear the - // floating properties of inline images immediately after a node's content. - return $text .'
'; -} - function theme_img_assist_popup($content, $attributes = NULL) { $title = drupal_get_title(); $output = '' . "\n"; Index: img_assist_tinymce.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/img_assist_tinymce.js,v retrieving revision 1.7 diff -u -p -r1.7 img_assist_tinymce.js --- img_assist_tinymce.js 1 Feb 2009 09:21:08 -0000 1.7 +++ img_assist_tinymce.js 12 Aug 2009 07:24:54 -0000 @@ -1,19 +1,4 @@ // $Id: img_assist_tinymce.js,v 1.7 2009/02/01 09:21:08 sun Exp $ -/** - * This javascript file allows img_assist to work with TinyMCE via the - * drupalimage plugin for TinyMCE. - * This file is used instead of img_assist_textarea.js if img_assist is called - * from the drupalimage plugin. - * Additional JS files similar to img_assist_textarea.js and - * img_assist_tinymce.js could be created for using img_assist with other - * WYSIWYG editors. Some minor code changes to the menu function in - * img_assist.module will be necessary, at least in img_assist_menu() and - * img_assist_loader(). - */ - -// This doesn't work right. tiny_mce_popup.js needs to be loaded BEFORE any -// setWindowArg() commands are issued. -// document.write('<\/script>'); // get variables that were passed to this window from the tinyMCE editor var nid, captionTitle, captionDesc, link, url, align, width, height; Index: plugins/img_assist/img_assist.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/plugins/img_assist/img_assist.js,v retrieving revision 1.5 diff -u -p -r1.5 img_assist.js --- plugins/img_assist/img_assist.js 13 Jun 2009 01:17:21 -0000 1.5 +++ plugins/img_assist/img_assist.js 12 Aug 2009 07:50:45 -0000 @@ -55,7 +55,7 @@ Drupal.wysiwyg.plugins.img_assist = { // 'class' is a predefined token in JavaScript. node['class'] = 'img-assist drupal-content'; node.src = Drupal.settings.basePath + 'index.php?q=image/view/' + node.nid; - node.alt = 'nid=' + node.nid + '|title=' + node.title + '|desc=' + node.desc; + node.alt = 'iid=' + node.iid + '|nid=' + node.nid + '|title=' + node.title + '|desc=' + node.desc; if (node.link.indexOf(',') != -1) { var link = node.link.split(',', 2); node.alt += '|link=' + link[0] + '|url=' + link[1];