Electronic Collaboration Expertise since 1994

Facebook Photo Uploader in Fedora 16

January 28 2012 01:56:27 PM
Running Fedora 16 PAE with Firefox 9 and the Adobe Flash plugin, I found that the facebook photo uploader control was not working. The flash plugin itself seemed fine, but just didn't want to work with facebook. I found that the solution was to remove nspluginwrapper. After that it worked like a charm.

Random Images from an Image Field in a Block in Drupal 7

March 24 2011 11:59:55 AM
The Problem:
Displaying a random image from the image field in a certain node type (where not every node has an image) in a block.

My Solution:

1. First thing is create a view with the following "Default" settings:
  • Under "Basic settings" set the "Use page" setting to "1 item", i.e. "Display a specified number of items" and set that number to "1" with an offset of "0"
  • Under "Advanced settings", "Caching" should be set to "None"
  • Under "Style Settings", "Style" should be "Unformatted" and "Row style" should be "Fields"
  • Under "Fields", set to your image field (in my case this is called "field_image")
    • The formatter should be "Image" with an Image style appropriate to your application. Everything else is going to be overridden in a theme-hint that I'll explain further down.
  • Under "Filters" add a "Node" filter, selecting "Node: Type" and then set the "Node:Type" filter settings to "Is one of" and the node type(s) you want to use are selected.
  • Add a "Fields" filter and chose "Fields: [your field name] - value" and set the operator for the fields filter to "is not empty (NOT NULL)"
2. Add a "Block" display type (select "Block" fromt the drop-down above the "Add display" button and click the button.
  • Under "Block settings" set "Caching" to "Do not cache"
3. While still viewing the "Block" display settings, click the "Theme: Information" link in the "Style settings" - look for the very last theme-hint which should be in the format, "views-view-field--[view-machine-name]--[block-machine-name]--entity-id.tpl.php  ...for example if your view's machine name is "random_image_view" and the block is "homepage_feature_block" the theme hint would be "views-view-field--random-image-view--homepage-feature-block--entity-id.tpl.php"
4. Be sure you have saved the view.
5. Create a file in your theme template directory with the name of the theme-hint from above.
  • To work with the image URL directly you need to extract it from the view output. Since the view is only displaying one image, this is pretty easy. I used the following code:
    preg_match("/src=\"(.+?)\"/i",$output, $matches);

    $src = $matches[1];
  • Now that you have the URL of the image you can do whatever you want to display it. In my case I made it the background of a div that filled the block, like so:
    <
    div id="featured-bgimage" style="background: #ddd1a4 url('<?php echo $src; ?>') repeat-x center top;">&nbsp;</div>
    But what you do with it depends entirely on your design.
The last thing you want to do, of course, is set up a block to display your view's block. I'll assume you know how to do that.

Creating a Page Template Suggestion for a Specific Node Type in Drupal 7

March 17 2011 01:51:49 PM
Add the following function to the template.php for your theme:

function yourthemename_preprocess_page(&$vars, $hook) {
 if (isset($vars['node'])) {
 // If the node type is "blog" the template suggestion will be "page--blog.tpl.php".
  $vars['theme_hook_suggestions'][] = 'page__'.$vars['node']->type;
 }
}

 
Change the "yourthemename" in the function name to match the name of your theme.

Showing Only the First Image in the Teaser for a Drupal 7 Image Field

February 22 2011 11:47:35 AM
By default, a Drupal 7 image field that is set to contain multiple images, will display all of the images in both the teaser and full node view. While desirable, there is no option when creating a view to only show the first image in the teaser. This can be accomplished, however, with the new Drupal 7 field-level template-hint.

In order do this globally for a field named "field image" the following code in a template file named "field--field_image.tpl.php"

<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
 <?php if (!$label_hidden) : ?>
   <div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>:&nbsp;</div>
 <?php endif; ?>
 <div class="field-items"<?php print $content_attributes; ?>>
 <?php if ($element['#view_mode']=="teaser") { ?>
     <div class="field-item even"<?php print $item_attributes[0]; ?>><?php print render($items[0]); ?></div>
 <?php } else { ?>
   <?php foreach ($items as $delta => $item) : ?>
     <div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; ?>"<?php print $item_attributes[$delta]; ?>><?php print render($item); ?></div>
   <?php endforeach; ?>
  <?php } ?>
 </div>
</div>


UPDATE: Note that the views module now includes an option for which values to display out of multi-value fields that takes precedence over the field-level template hint.

Initialize a Null NotesDocumentCollection

May 22 2010 01:31:18 PM
There are times when it is handy to start will a null collection in a NotesDocumentCollection., for example when you want to add documents to a collection programmatically based on something other than selected documents in a view.

Two good methods for doing this are:

Method 1:

Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
               
Set db = session.CurrentDatabase
Set collection = db.GetProfileDocCollection("The name of a non-existent profile document")


Method 2:

Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim futureDate As New NotesDateTime("01/01/3001")
               
Set db = session.CurrentDatabase
Set collection = db..Search({@Nothing},futureDate, 0)

Method 1 is my usually preferred method if the database does not have a large number of profile documents.
Method 2 can be faster if there are a large number of profile documents (i.e. tens of thousands or more.)