Revision: 1400 Author: sebastien.lelong Date: Tue Oct 20 01:48:33 2009 Log: first draft for JAPP Drupal module (JAPP is a nice acronym for Jallib Automated Publishing Process. This way, this looks very serious, professional and powerfull...) http://code.google.com/p/jallib/source/detail?r=1400
Added: /trunk/tools/japp /trunk/tools/japp/README /trunk/tools/japp/japp /trunk/tools/japp/japp/japp.info /trunk/tools/japp/japp/japp.module ======================================= --- /dev/null +++ /trunk/tools/japp/README Tue Oct 20 01:48:33 2009 @@ -0,0 +1,5 @@ +This directory contains anything related to JAPP. + +(J)allib (A)utomated (P)ublishing (P)rocess is a workflow to automatically +create output document from DITA XML files, and potentially publish them +on justanotherlanguage.org website. ======================================= --- /dev/null +++ /trunk/tools/japp/japp/japp.info Tue Oct 20 01:48:33 2009 @@ -0,0 +1,8 @@ +; $Id $ +name = JAPP +description = Jallib Automated Publishing Process, publish from emails, handle specific cases related to jallib and DITA XML documents +core = 6.x +dependencies[] = mailhandler +dependencies[] = mailsave +package = Jallib + ======================================= --- /dev/null +++ /trunk/tools/japp/japp/japp.module Tue Oct 20 01:48:33 2009 @@ -0,0 +1,96 @@ +<?php + +/** + + Title: JAPP Drupal module + Author: Sebastien Lelong, Copyright (c) 2009, all rights reserved. + + This file is part of jallib (http://jallib.googlecode.com) + Released under the BSD license (http://www.opensource.org/licenses/bsd-license.php) + + Description: this module implements several hooks from mailhandler and mailsave + 3rd party modules, in order to publish HTML document to jal website, using mails. + +*/ + +/** + This Drupal module implements specific mailhandler & mailsave hooks, + to deals with document publishing from email, related to jallib project + (and other projects like jaluino). This is part of the + Jallib Automated Publishing Process (JAPP) + + Specifically: + + - catch "path" command to determine "nid",with hook_mailhandleri(). + With basic mailhandler + behavior, submitting the same document, with the same URL would actually + create a new document, and force URL to be differen (typically add numbers). + In JAPP, when submitting a same document, with the same ULR, a new revision + must be created. mailhandler can do this, you just have to specify "nid" + (node ID). The problem is "nid" can't be known while submitting email. So, + instead we'll look at "path" command, to determine corresponding node. If + a node exists, then hook adds a "nid" command, so mailhandler will create + a new revision. If node does not exists, it keeps things as is, so a new + node will be created. + + - implement hook_mailsave() to put all attachments to a specific location + (like "/sites/default/files/japp") +*/ + +/** + * Implementation of hook_perm(). + */ +function japp_perm() { + // for now, no perms + return array(); +} + + +/** + * Implementation of hook_menu(). + */ +function japp_menu() { + + $items = array(); + return $items; +} + + +/** + * Implementation of hook_mailhandler() + */ +function japp_mailhandler($node, $result, $i, $header, $mailbox) { + if(empty($node->path)) { + watchdog("japp","Submitted node %title does not have path, can't know which is corresponding node in database", + array("%title" => $node->title),WATCHDOG_ERROR); + return FALSE; + } + // The idea is to determine, given submitted node, if it's already in database. + // For this, we'll search according to its path (there can be only one path for a node) + // Note: node doesn't have a specific language set, I think this should be ok... + // Still we need to use "language" column to hit table's index + $sql = "SELECT src FROM {url_alias} WHERE dst = '%s' AND language = ''"; + // honor SQL rewrite by other modules, just in case + $result = db_result(db_query(db_rewrite_sql($sql),$node->path)); + if($result) { + $node_nid = split("/",$result); + if(count($node_nid) != 2 || $node_nid[0] != "node") { + watchdog("japp","Source URL for '%path' is '%src', I expect to have something like 'node/77' in it...", + array("%path" => $node->path,"%src" => $node_nid),WATCHDOG_ERROR); + return FALSE; + } + $node->nid = (int)$node_nid[1]; + // set revision to something, so Drupal knows it has to create a new revision ! + $node->revision = 'vid'; + watchdog("japp","Creating a new revision for node %title with path %path", + array("%title" => $node->title,"%path" => $node->path)); + } else { + // no such path, means a new node. Just let mailhandler does its job + watchdog("japp","Creating a new node for node %title with path %path", + array("%title" => $node->title,"%path" => $node->path)); + } + + return $node; +} + + --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jallib" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/jallib?hl=en -~----------~----~----~----~------~----~------~--~---
