Peter's Blog 29.7.2004

2004-07-29

Wrapping text around Photos

The following can be used in PyDS to wrap text around pictures:

$macros.imageTag( 'images/picture.jpg', align='left')

This makes me happy.

posted at 16:10:56    #    comment []    trackback []
 

Posting Work Blog entrys on Public Blog.

At work I am using Drupal as a CMS for blogging, organising project related information etc. I feel it is more suited to a collaborative role than PyDS which is essentially a private tool for publishing to a community server. The community servers available do not appear to be strong CMS systems.

Drupal is very nicely written and even I, a PHP n00b, have managed to write a Drupal module that enables me to email a posting from the work server to my home PyDS installation where it can be posted to my personal/public blog. The email->PyDS gateway that I set up for photo blogging does the posting of the email to the blog.

Main stubling block encountered was when random pieces of the email message received were missing. This turned out to be because the message was stored in the database with \r line delimiters rather than \n. When the message was transmitted this looked to the email stuff like VERY long lines so it proceeded to screw up. I'm not sure where these came from, whether the web browser uses these in text fields or what. This script turns them to \n's which everybody loves (except dos/mac zealots).

Here is my Drupal 'sendhome.module' which does the posting.



<?php
/*
 * Add option to send postings to home.
 * Inspired by the emailpage module but simplified.
 * No admin options, edit this module.
 */

function sendhome_help($section = 'admin/help#sendhome') {
  $output = "";

  switch ($section) {
  case 'admin/system/modules#description':
    $output = t("Send page home");
    break;
  }
  return $output;
}

function sendhome_link($type, $node=0, $main) {
  global $user;

  $links = array();

  /*
   * If logged in user is moi, give me the option of sending this home.
   */
  if( $user->name == 'my_drupal_user_name') {
    if (($type == "system")) {
    // URL, page title, func called for page content, weight, 1 = don't disp menu
      menu("sendhome", t("Send Page Home"), "sendhome_page", 1, MENU_HIDE);
    }

    $links[] = l(t("Send Page Home"), "sendhome/confirm/$node->nid", array("title" => t("Send Page Home.")));
  }
  return $links;
}

function sendhome_page() {
  /*
   * Get function parameters.
   */
  $op = $_POST[ "op"];
  $edit = $_POST[ "edit"];

  if( empty($op)) {
    /*
     * In initial link nid is in the url
     */
    if( arg(1) == 'confirm') {
      $nid = arg(2);
    }
  } else {
    /*
     * From the send button the nid is in a hidden field.
     */
    $nid = $edit[ "nid"];
  }

  /*
   * Search db for nodes.
   */
  $nodes = db_query("SELECT nid, title, teaser, created FROM {node} WHERE nid = %d", $nid);

  drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('View'), "node/view/$nid")));

  while ($node = db_fetch_object($nodes)) {
    /*
    ** Load the specified node:
    */
    $item = node_load(array('nid' => $node->nid));

    /*
     * Add the title and the body to the output under construction.
     */
    $output .= $item->title;
    $output .= "\n";
    /* Pass body through filters to create html */
    $output .= check_output( str_replace( '<!--break-->', '', $item->body));
  }
  /*
  * Maybe it's my fault for using windows but \r line delimiters lead to VERY
  * long lines that don't make it through email without random bits missing.
  */
  $output = str_replace( "\r", "\n", $output);
  if ($op != t("Send")) {
    /*
     * Display the posting that is to be sent and a send button.
     */
    $output = "<div class=\"node\">$output</div>";
    $output .= form( form_submit(t("Send")) . form_hidden("nid", $nid));
    print theme( "page", $output, "Post Message Home?");
  }
  else {
    /*
     * Set email parameters.
     */
    $strTo = "me@home.com";
    $strFrom = "me@work.com";
    $strMagicSubjectLine = "post this for me";

    /*
     * Send operation so send the post and show a 'Done' page.
     */
    mail( $strTo, $strMagicSubjectLine, $output, "From: $strFrom\r\n", "-f$strFrom");
    print theme( "page", '', "Posted Message");
  }
}

?>
posted at 14:09:20    #    comment []    trackback []
July 2004
MoTuWeThFrSaSu
    1 2 3 4
5 6 7 8 91011
12131415161718
19202122232425
262728293031 
Jun
2004
 Aug
2004

A blog documenting Peter's dabblings with Python, Gentoo Linux and any other cool toys he comes across.

XML-Image Letterimage

© 2004, Peter Wilkinson

Bisi and me