Index: inline.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/inline/inline.module,v retrieving revision 1.19.2.13 diff -u -p -r1.19.2.13 inline.module --- inline.module 5 Jul 2008 00:20:40 -0000 1.19.2.13 +++ inline.module 17 Aug 2008 14:30:45 -0000 @@ -1,6 +1,10 @@ Sometimes a user may want to add an image or a file inside the body of a node. This can be done with special tags that are replaced by links to the corresponding uploaded file. If the file is an image, it will be displayed inline, otherwise a link to the file will be inserted. To enable this feature and learn the proper syntax, visit the filters configuration screen.
', array('!filters' => url('admin/filters'))); - + case 'filter#short-tip': return t('You may add links to files uploaded with this node using special tags', array('!explanation-url' => url('filter/tips', NULL, 'image'))); - + case 'filter#long-tip': return t('You may link to files uploaded with the current node using special tags. The tags will be replaced by the corresponding files. Syntax: [inline:file_id]. Parameter: file_id represents the file uploaded with the node in which to link, assuming that the first uploaded file is labeled as 1 and so on.
If the file is an image, it will be displayed inline, otherwise a link to the file will be inserted.
'); @@ -49,25 +53,25 @@ function inline_help($section = 'admin/h */ function inline_settings() { $form = array(); - + // Check if Inline filter is enabled - $inline_activated = false; + $inline_activated = FALSE; foreach (filter_formats() as $format) { foreach (filter_list_format($format->format) as $filter) { if ($filter->module == 'inline') { - $inline_activated = true; + $inline_activated = TRUE; break 2; } } } - if ($inline_activated == false) { + if ($inline_activated == FALSE) { drupal_set_message(t('Inline filter is not yet enabled for at least one input format.', array('!formats' => url('admin/settings/filters'))), 'error'); } - + $form['inline']['upload']['image_link'] = array( '#type' => 'fieldset', '#title' => t('Image output'), - '#collapsible' => true, + '#collapsible' => TRUE, '#description' => t('Note: Images are only processed, if a tag is referencing them. However, there is a auto-inline feature to inline all uploaded images automatically. Auto-inline can be enabled for certain content types.', array('!content-types' => url('admin/content/types'))), ); $form['inline']['upload']['image_link']['inline_link_img'] = array( @@ -79,7 +83,7 @@ function inline_settings() { '1' => t('Display image with a link to the image file') ), ); - + $imagecache_path = ''; $presets = array(); if (module_exists('imagecache')) { @@ -100,10 +104,10 @@ function inline_settings() { $form['inline']['upload']['image_scaling'] = array( '#type' => 'fieldset', '#title' => t('Image dimensions and scaling'), - '#collapsible' => true, + '#collapsible' => TRUE, '#description' => (module_exists('imagecache') ? t('Select the Imagecache presets to use for inlined images.', array('!presets' => $imagecache_path)) : t('Note: If Imagecache module is installed, Inline provides support for image scaling.', array('!imagecache' => url('http://drupal.org/project/imagecache')))), ); - + // If Imagecache module exists and is enabled, we assume that we want to use // the improved image handling instead of our own. if ($presets) { @@ -138,13 +142,13 @@ function inline_settings() { '#description' => t('This setting limits the dimensions of displayed images in pixels. They will not be resized. Images exceeding these dimensions are automatically not displayed.', array('!content-types' => url('admin/content/types'))), ); } - + return system_settings_form($form); } /** * Implementation of hook_form_alter(). - * + * * Allows to enable/disable auto-inline support for each content type. */ function inline_form_alter($form_id, &$form) { @@ -166,23 +170,23 @@ function inline_form_alter($form_id, &$f /** * Implementation of hook_filter(). - * + * * Since Inline needs to know which files are attached to a processed node, the * original text is simply returned here. - * - * @see inline_nodeapi(). + * + * @see inline_nodeapi() */ function inline_filter($op, $delta = 0, $format = -1, $text = '') { switch ($op) { case 'list': return array(0 => t('Inline file filter')); - + case 'description': return t('Substitutes [inline:xx] tags with the xxth file uploaded with the node.'); - + case 'prepare': return $text; - + case 'process': return $text; } @@ -191,7 +195,7 @@ function inline_filter($op, $delta = 0, /** * Implementation of hook_filter_tips(). */ -function inline_filter_tips($delta, $format, $long = false) { +function inline_filter_tips($delta, $format, $long = FALSE) { if ($long) { return ''. t(' You may link to files uploaded with the current node using special tags. The tags will be replaced by the corresponding files. For example: @@ -219,16 +223,16 @@ function inline_filter_tips($delta, $for /** * Implementation of hook_nodeapi(). - * + * * Substitutes Inline tags with the corresponding files or images in front of * node_view(). * Replaces numeric file references in Inline tags (i.e. [inline:1]) with named * file references (i.e. [inline:foo.jpg]) upon node preview and node save. - * + * * @todo Break processing at all if Inline filter is not enabled. */ function inline_nodeapi(&$node, $op, $arg) { - if (!is_array($node->files)) { + if (!(isset($node->files) && is_array($node->files))) { return; } switch ($op) { @@ -238,8 +242,12 @@ function inline_nodeapi(&$node, $op, $ar // Only nodes with Inline filter in the format may be processed. foreach (filter_list_format($node->format) as $filter) { if ($filter->module == 'inline') { - $node->teaser = _inline_substitute_tags($node, 'teaser'); - $node->body = _inline_substitute_tags($node, 'body'); + if (isset($node->teaser)) { + $node->teaser = _inline_substitute_tags($node, 'teaser'); + } + if (isset($node->body)) { + $node->body = _inline_substitute_tags($node, 'body'); + } break; } } @@ -247,11 +255,15 @@ function inline_nodeapi(&$node, $op, $ar $node = _inline_auto_add($node); } return; - + case 'prepare': case 'submit': - $node->teaser = _inline_replace_numbers($node, 'teaser'); - $node->body = _inline_replace_numbers($node, 'body'); + if (isset($node->teaser)) { + $node->teaser = _inline_replace_numbers($node, 'teaser'); + } + if (isset($node->body)) { + $node->body = _inline_replace_numbers($node, 'body'); + } return; } } @@ -285,11 +297,11 @@ function _inline_fileobj(&$node, $id) { /** * Change file path of new files for previews. - * + * * New files are stored in a temporary upload directory until the content * is saved. We alter the file object accordingly, so such files may be * displayed if the temporary directory is publicly accessible. - * + * * @todo Prepend 'system/' for private files support. */ function inline_prepare_file_object($file) { @@ -309,7 +321,7 @@ function inline_prepare_file_object($fil function theme_inline_as_link($file) { // Prepare link text with title or filename. $linktext = ($file->title ? $file->title : $file->filename); - + return l($linktext, file_create_url($file->filepath), array('title' => t('Download: @name (@size)', array('@name' => $file->filename, '@size' => format_size($file->filesize))))); } @@ -320,7 +332,7 @@ function theme_inline_img($file, $field) // Prepare link text with inline title, file description or filename. $title = (!empty($file->title) ? $file->title : (!empty($file->description) ? $file->description : $file->filename)); $inline_preset = $field == 'teaser' ? 'inline_teaser_preset' : 'inline_full_preset'; - + if (module_exists('imagecache') && variable_get($inline_preset, '') != '') { $image = theme('imagecache', variable_get($inline_preset, ''), @@ -338,7 +350,7 @@ function theme_inline_img($file, $field) array('class' => 'inline') ); } - + if (variable_get('inline_link_img', '1')) { $attributes = array( 'class' => 'inline-image-link', @@ -349,7 +361,7 @@ function theme_inline_img($file, $field) else { $html = $image; } - + return $html; } @@ -383,7 +395,7 @@ function theme_inline_add_to_body($node, /** * Automatically add all images to configured node views. - * + * * This feature can be configured per content-type. */ function _inline_auto_add($node) { @@ -401,7 +413,7 @@ function _inline_auto_add($node) { } } break; - + case 2: // Display only in body. foreach ($node->files as $fid => $file) { @@ -415,7 +427,7 @@ function _inline_auto_add($node) { } } break; - + case 3: // Display in teaser and body. foreach ($node->files as $fid => $file) { @@ -436,12 +448,12 @@ function _inline_auto_add($node) { /** * Replace all Inline tags with their corresponding files or images. - * + * * @param object $node * The node to process. * @param string $field * The node field to process. - * + * * @return string * The processed content of the given node field. */ @@ -511,6 +523,9 @@ function _inline_replace_numbers($node, // Node form prepare is an object. $filename = $node->files[$key]->filename; } + if (!isset($match[3])) { + $match[3] = ''; + } $node->$field = str_replace($match[0], '['. $match[1] .':'. $filename . $match[3] .']', $node->$field); } } @@ -536,14 +551,14 @@ function _inline_decide_img_tag($file) { else { // Read maximum dimension settings. list($maxwidth, $maxheight) = explode(',', variable_get('inline_img_dim', '150,150')); - - if ($file->preview) { + + if (!empty($file->preview)) { list($width, $height) = getimagesize($file->real_path); } else { list($width, $height) = getimagesize($file->filepath); } - + if (($width && $height) && ($width <= $maxwidth && $height <= $maxheight)) { return TRUE; }