2008-03-13

CakePHP 1.2 は、webservices に対応しない。

CakePHP アップデートで携帯ページ NG の件の「次回」は、割と早い時期にやってきそうです。

ソースコードリポジトリの 1.2.x.x ブランチのChangeset [6453] で webservices 関係がばっさり削除されてます。1.2 リリースでは、確実に別の実装を行わないとだなぁ。

これは、別件調べ事のついででした。それは、PostgreSQL を使っている場合に UPDATE 文に alias が入って失敗するというもの。

http://cakephp.jp/modules/newbb/viewtopic.php?post_id=1814&topic_id=934&forum=6

こちらでも議論がされていますが、1.2.0.6311-beta のはまりねたらしいです。部分的に差し替えようかと思ったのですが、変更範囲がかなり広い。幸か不幸か、携帯ページを使っていなかったので cake ディレクトリを HEAD Revision に全とっかえして、UPDATE 文は、通るようになりました。まだ、時間的に余裕があるから良いけど、今後も、こんなことはありそうだから、ユニットテストはきちんと書いておこう。

2008-03-12

CakePHP アップデートで携帯ページ NG

CakePHP で作成したサイトの携帯ページを CakePHP 携帯用ビューを表示する(Shin x blog さん) などを参考に実装していました。当初は、1.2.0.5875-pre-beta を使ってうまく行っていたのですが 1.2.0.6311-beta にアップデートしたところ、文字化けに見舞われました。念のため Subversion にブランチして作業していたのですぐに戻せるのですが、悔しいので少し調べてみました。

状況を落ち着いてみてみると、どうやら View は、webservice のものが選択されているが、Layouts が通常のものの模様。render まわりと当たりをつけて cake/libs/view/view.php を diff してみたら、かなり大幅に変ってる。他は、ほぼ問題ないので _getViewFileName と _getLayoutFileName のみに着目すると、やっぱり、webservices 判定が _getViewFileName にはあるが、_getLayoutFileName からはなくなってました。

@@ -821,6 +821,9 @@
}
$subDir = null;

+ if (!is_null($this->webservices)) {
+ $subDir = strtolower($this->webservices) . DS;
+ }
if (!is_null($this->layoutPath)) {
$subDir = $this->layoutPath . DS;
}


こんな修正で動くようにはなります。しかし、コアに変更入れるのは、さて、どうしたものか...



cake/libs/router.php には 「webservice は、非推奨で将来的にはサポートしなくなるよ。Router::parseExtensions() を使ってね。」という記述がありますね。1.2 系で作業始めたときも情報の少なさに「しくじったか?」とは、思ったのですが...



次回からがんばります。

2008-03-05

How to make an exhibit from data fed directly from a Google Spreadsheet

原文

Google Spreadsheet から直接供給されるデータから exhibit する方法

This tutorial shows you how to feed data directly from a Google Spreadsheet rather than from a file. The advantage of this is that you can edit your data in Google Spreadsheets' user interface. Here is an example.

Formatting the Data

You need to make sure that your Google spreadsheet follows a particular format, which can be seen here:

あなたはあなたの Google スプレッドシートが特定のフォーマットに従うことを確認する必要があります。そして、それはここで見ることができます:

 http://spreadsheets.google.com/pub?key=pLvsUS-CftHo21r-0xjKvVA


The first row contains the property names wrapped in {}. You can specify the value type for a property, e.g., {rating:number}. You can have multiple values for each field and they should be separated by semicolons, e.g., "Drama; Epic". If you want to tell Exhibit not to split a field by semicolons, add ":single" to the column header, e.g., {plot:single}.



最初の行は、{} の中に包まれたプロパティ名を含みます。プロパティの型を定義することも出来ます、例えば、{rating:number}。複数の値を同一フィールドに持つことができ、それらは、セミコロンで区切られます、例えば、"Drama; Epic"。もし、セミコロンでフィールドを分割しないよう Exhibit に指示したい場合は、カラムヘッダーに ":single" を追加してください、例えば、{plot:single}



Important note! Be sure to make the first column {label}. Otherwise Exhibit will use what it finds in cell A1 as {label}, since the Google Spreadsheet export format does not convey the data listed in that cell.



重要な注意! 必ず最初のカラムとして{label}を作って下さい。さもないと、Google スプレッドシートエクスポート形式がそのセルにリストされたデータを伝達しないので、Exhibit は、A1 セルで見つけたものを {label} として使います。



Getting the Feed



First, open your Google spreadsheet and then click on the Publish tab on the right. If it's not published yet, click Publish Now. Then you will see something like this:



まず最初に、あなたの Google スプレッドシートを開き、次に、右の方の Publish タブをクリックしてください。 まだ発行していない場合は、 Publish Now をクリックしてください。 すると、あなたはこのような物を見るでしょう。



 Publish at: http://spreadsheets.google.com/pub?key=pLvsUS-CftHo21r-0xjKvVA


Click on the URL to get a new window with your spreadsheet in view only mode.



URL をクリックすると表示のみモードのスプレッドシートの新しいウィンドウが開きます。



For Firefox


If you're using Firefox, right click anywhere on the page and choose View Page Info. Then click on the Links tab, and look for a row in which Name is "alternate", Type is "Related Item", "Address" looks something like this:



 http://spreadsheets.google.com/feeds/list/o08841867754116283182.6102151849127695926/od6/public/basic


Right click on that row and choose Copy. Then close the dialog box. What you've copied is the URL of the feed of the spreadsheet.



For Internet Explorer


Right click somewhere on the page and choose View Source. Then use the source editor's Find command to search for "feeds". That should land you in the middle of the feed URL. Copy that URL to the clipboard and close the source editor.



Setting up the Exhibit



To link in your data, paste in that feed URL and append ?alt=json-in-script to it. Then, make sure the data link has type="application/jsonp" (note the "p") and ex:converter="googleSpreadsheets":



 <link rel="exhibit/data" 
type="application/jsonp"
href="http://spreadsheets.google.com/feeds/list/o08841867754116283182.6102151849127695926/od6/public/basic?alt=json-in-script"
ex:converter="googleSpreadsheets" />


This is assuming that you are using Exhibit version 2.0.



Re-publishing



You can set your Google Spreadsheet to re-publish every so often, or you have to manually click the Re-publish button in Google Spreadsheets.



But that's it!

2008-02-12

Plugin moblog

Description

This plugin allows to easily post new articles via email or even MMS in those terminals that support this feature. The plugin can also handle attachments such as images or videos, and those will first be added as new files to the resource centre and then a link to these files will be added to the contents of the post. The text contents of the email will be published as a post in the main page, and assigned to the category that we select in the plugin configuration page.

このプラグインは、この特徴をサポートするそれらの端末にメールやMMSを通して簡単に新しい記事のポストを可能とします。プラグインはイメージまたはビデオのような添付を取り扱うこともでき、最初に新しいファイルとしてresource centre に追加し、それから、これらのファイルへのリンクをポストの中身に加えます。メールのテキストコンテンツは、メインページのポストとして発行されて我々がプラグイン構成ページで選ぶカテゴリーに割り当てられます。

How it Works

Email or MMS messages are sent to an email address that is especially set up for moblogging to LifeType (one e-mail address can be used to post to more than one blog. But if you use Realtime publishing it's also possible to use dedicated e-mail addresses per blog).

Attachments are extracted from the message and processed. All attached files will be saved to the resource centre and in the case of images, they will processed as any other image and different thumbnails will be generated. Once attachments have been processed, a link to the file or image will be added to the final post that will be published in the blog page.

It supports two different methods for publishing posts:

  • Realtime publishing (push method)
  • Batch publishing (pull method)

Sending Messages

Moblogged messages must have some mandatory information in them so that the plugin can identify who is sending the message and where it should be posted. A sample message could look like this:

USER: youruser
PASS: yourpassword
BLOG: your blog name
This is a very simple example message, which is
being sent to blog 'your blog name', on behalf of
user 'youruser' whose password is 'yourpassword'.

This message would post a new article to blog your blog name for user youruser and it would try to authenticate using password yourpassword. Needless to say, the lines containing this kind of information will be removed before the post is added to the blog.

In order to specify a topic for the post, we can use in order of importance:


  1. A TOPIC: yourtopic line in the body of the message.
  2. The 'Subject' header (if we are sending an email message)
  3. The first 50 characters of the body of the message, stripped of all markup

Additionally, we can use '"BLOGID: blog_id instead of BLOG: your blog name in the body of the message, if we know the internal identifier of the blog. Using the blog id is obviously much shorter to type in mobile devices.

In order to summarize, these are the "commands" that can be used within the message body:


  • USER: the name of the user on behalf of whom this article is going to be posted
  • PASS: the password in order to authenticate
  • BLOG: the name of the blog to where this is going to be published. It can include spaces if necessary and can be in either lower case or upper case.
  • BLOGID: instead of typing the blog name, we can use the blog identifier if we know it. Much easier to type.
  • TOPIC: allows to specify a topic for the post.

From the items above, USER, PASS and either BLOG or BLOGID are necessary in every message and please keep in mind that each one of these has to appear in its own line.

It is not possible to configure to which category posts are added in the message body, only via the plugin configuration page (see "User configuration options" below).


Configuration


Before using this plugin, move the files moblog.php and moblogbatch.php from plugins/moblog/ to the root folder of LifeType (at the same level as index.php, admin.php, rss.php and so on). It is possible to leave it there by default but all examples in this document refer to moblog.php being in the root folder of LifeType.


Batch Publishing


This is the method you may prefer, if your blog is set up on a shared hosting or if you don't have access to the mailserver configuration and/or Curl. So if you don't know what Curl is, you probably want to use batch publishing. ;-) All you need to get up and running is POP3 access to an email account. Optionally access to some kind of cronjob can improve performance.

WARNING: you need an email account that is exclusively used for your Moblog. All messages in your inbox will be deleted no matter if they are valid moblog posts and get published or not. This will keep your moblog inbox clean from spam.


Configuring Batch Publishing

After installing the plugin you will get a new menu entry unter "Administration" called "Moblog Batch Settings". There are two ways to configure the batch publishing: Either you set up a batch job (aka "cronjob") that calls moblogbatch.php to check for new moblog posts or you let LifeType do the work uppon visitor requests ("Pseudobatch"). Needless to say that the second version may have a performance impact on visitors each time LifeType checks for new moblog posts. Thats why we recommend setting up a cronjob.


Batch Setup

As explained on the configuration page, you should set the "Pseudobatch" option to "disable" if you would like to set up a cronjob. A cronjob simply calls moblogbatch.php within a predefined interval. You can either use your servers cronjob feature or use one of the free cronjob services out there.

Your call to the script may look similar to this:

 /usr/local/bin/php5.cgi -d allow_url_fopen=1 /home/username/www/lifetype/moblogbatch.php silent

Pseudobatch Setup

The pseudobatch is the least efficient but the most simple method of setting up the moblog plugin. If you set the pseudobatch to, say, 10min, every visitor that requests one of your blogs pages will initiate a call to moblogbatch.php in the background, if it has been more than 10min since the last check to your moblog e-mail account.


Realtime Publishing


In order to get the push-method to work, it is necessary to have access to an email server running Postfix, Sendmail or similar SMTP server that accepts forwarding incoming messages to external commands via virtual (aliased) email addresses.

Additionally, the curl tool is also necessary in order to be able to forward email messages to a web server.

The e-mail address will be a virtual one, since the contents of the incoming email will be passed via standard input to curl, which will make an HTTP request to our moblog.php script. Moblog.php is the entry point to the functionality, and implements some code which is capable of parsing emails and extracting attachments from it.


Configuring Curl

curl is a commonly available tool in most Linux distros so there should not be any problem getting it to work.


Configuring the Email Alias

A dedicated email address is needed in order to use this functionality. The email address will be set up in the aliases file used by our SMTP server. Its location of this file may vary but it should be something like /etc/aliases or /etc/mail/aliases.

The new alias address should look like this:

moblog: "|curl -F message='<-' http://yourhost.com/moblog.php"

Once this new alias has been added, please do not forget to run the newaliases command.

In order to test this, please send a message to moblog@yourhost.com (please replace host names wherever relevant) If you wish to use a different email address, please replace moblog in the example above with your new address.

It is also worth mentioning that with this current configuration, this email address can be used as some kind of gateway for as many blogs as needed available in the current site, so there is no need to create a new email address for each one of our blog users (although this is possible, see the last section of this page)

If case of problems, one good way to debug possible SMTP server issues is by keeping an eye on the SMTP server log file and see if there is any error message in there.


User Configuration Options


The plugin adds a new configuration page for each blog under the Control Centre->Blog Settings, and it is necessary to first enable the plugin before using it.

In the plugin configuration page we can also configure the following things:


  • The article category to which new moblogged posts will be added. Just select one from the list of categories available in the blog.
  • The album to which attachments will be added.
  • When images are attached to images, this plugin will automatically include the image in the contents of the post, right below the content of the message. It is possible to choose how the image will be included in the post: as a small thumbnail, as a medium-sized thumbnail, or as full-size image. This setting defaults to a small thumbnail.

Compatibility List


Below you find a compatibility list of clients and mobile network operators. Let us know if you have tested the plugin with other clients or on other networks.


E-Mail Clients


  • Apple Mail.app 2.0
  • Microsoft Entourage 2004
  • Horde IMP
  • Microsoft Outlook 2000
  • Mozilla Thunderbird
  • Gmail
  • GMX

Mobile Devices (either e-mail or mms)


  • Nokia N91
  • Nokia 7610
  • Nokia 9500 Communicator
  • SonyEricsson P800
  • SonyEricsson K700i
  • SonyEricsson K750i
  • Nokia 3100 works, but has problems with encoding.
  • Siemens M65 works, but has problems with encoding, especially german characters called "Umlaute" (e.g. ä, ö, ü)

MMS to SMTP Gateways


  • Elisa (Finnland)
  • Swisscom (Switzerland)

The feasability of moblogging via MMS greatly depends on the operator. Most operators have MMS-to-SMTP gateways that can convert MMS messages to valid emails, that can be processed by any email clients. However, how these email messages are created greatly depends on the operator.

This feature has only been tested with the Finnish mobile operator Elisa. Its MMS to SMTP gateway will reformat MMS messages to mail messages with MIME content multipart/alternative with at least 4 MIME parts: an HTML part with some information about the message, a plain/text part with the text contents of the body of the message, the image attached (if any) and a SMIL file with information about how to play the presentation/MMS message.

This plugin is capable of handling this kind of message. It will ignore any text/html and application/smil MIME parts and will use the text/plain as the body of the message, as many as it can find (it will basically append one after each other). Image attachments will be processed as expected.

In case you manage to successfully use the plugin in a different network, please update this page with the operator name.


Advanced Configuration


Automatically Register an Album and Category


If you would like to automatically set up a default category and default folder for your users, some modifications to dofinishregister.class.php are needed:

// create a new default category called Moblog
$article2Categories = new ArticleCategories();
$article2Category = new ArticleCategory( Moblog, "", $newblogId, true );
$moblogCat = $article2Categories->addArticleCategory( $article2Category );
// create a new default folder called Moblog
$moblogAlbum = new GalleryAlbum(
$blogInfo->getId(), // id of the new blog
"Moblog", // new name
"Default category for moblog postings", // description
0, // no flags
0, // no parent id yet
, // date not needed, will be set when adding the album
Array(), // no properties
true // the album should appear
);
$albums = new GalleryAlbums();
$albums->addAlbum( $moblogAlbum );
//enable the moblog plugin for each new user by default
$blogInfo->setValue( "plugin_moblog_article_category_id", $this->_categoryId );
$blogInfo->setValue( "plugin_moblog_gallery_resource_album_id", $this->_albumId );
$blogInfo->setValue( "plugin_moblog_resource_preview_type", 1 );
$blogInfo->setValue( "plugin_moblog_enabled", 1 );

Forcing a certain blog ID and/or user name


If we find that typing USER:xxx, PASS:yyy and BLOG:zzz in every single message is too much (which could be a valid reason when using this plugin from mobile devices), it is possible to "hardcode" the user name and the blog identifier in the email alias, so we could rewrite the sample email alias from above as:

moblog: "|curl -F user=youruser -F blogId=1 -F message='<-' http://yourhost.com/moblog.php"

This means that we can also reduce the contents of messages that should be moblogged. The sample above could be reduced to the following contents, effectively removing the lines containing USER and BLOG:

PASS: yourpassword
This is a very simple example message, which is being sent to blog '
your blog name', on behalf of user 'youruser' whose password
is 'yourpassword'.

The new email alias will default to using 'youruser' as the user name and '1' as the blog identifier, and this means that it will not be necessary to include this information anymore in the body of the email message. However, it is still possible to override these default settings by including again a USER and/or BLOGID (or BLOG) line in the body of the message, since the contents of the message will always take more priority than whatever was configured in the email alias.

NOTE: Passwords cannot be hardcoded in the email alias for security reasons, since if somebody found out the email address that we are using for moblogging contents, it would mean free access for publishing stuff via email!


Enabling Logging


It is possible to tell the plugin to log messages to the standard log file (tmp/lifetype.log) for debugging purposes.

In the moblog.php file find the following line:

define( "MOBLOG_DEBUG", false );

and set it to true:

define( "MOBLOG_DEBUG", true );

Also make sure that the default logger is using the appender file instead of null, in config/logging.properties.php:

$config["default"] = Array( 
"layout" => "%d %N - [%f:%l (%c:%F)] %m%n",
"appender" => "file",
"file" => "tmp/lifetype.log",
"prio" => "debug"
);

The plugin will log a lot of information so keep an eye on the size of the log file.


Known issues



  • There could be potential issues related to character encodings, specially when it comes to encoded file names (in the case of files with Chinese file names)


  • If you are experiencing some problems with this plugin and all you can see in the logs is something like this:
12-10-2005 10:03:30 DEBUG - [mobloglogger.class.php:21 (logger:debug)] -- Initialized
12-10-2005 10:03:30 DEBUG - [mobloglogger.class.php:21 (logger:debug)] -- message --
12-10-2005 10:03:30 DEBUG - [mobloglogger.class.php:21 (logger:debug)] '<-'
12-10-2005 10:03:30 DEBUG - [mobloglogger.class.php:21 (logger:debug)] -- end --
12-10-2005 10:03:30 DEBUG - [mobloglogger.class.php:21 (logger:debug)] From REQUEST: user = - blogId =
12-10-2005 10:03:30 DEBUG - [mobloglogger.class.php:21 (logger:debug)] parseBody ---> body =
12-10-2005 10:03:30 DEBUG - [mobloglogger.class.php:21 (logger:debug)] There are 0 MIME parts available to parse
12-10-2005 10:03:30 DEBUG - [mobloglogger.class.php:21 (logger:debug)] subject is = No Topic
12-10-2005 10:03:30 DEBUG - [mobloglogger.class.php:21 (logger:debug)] user = ''
12-10-2005 10:03:30 DEBUG - [mobloglogger.class.php:21 (logger:debug)] blog id =
12-10-2005 10:03:30 DEBUG - [mobloglogger.class.php:21 (logger:debug)] topic = No Topic
12-10-2005 10:03:30 DEBUG - [mobloglogger.class.php:21 (logger:debug)] reply to =
12-10-2005 10:03:30 DEBUG - [mobloglogger.class.php:21 (logger:debug)] body =
12-10-2005 10:03:30 DEBUG - [mobloglogger.class.php:21 (logger:debug)] User did not authenticate correctly.
12-10-2005 10:03:30 DEBUG - [mobloglogger.class.php:21 (logger:debug)] Response message sent!

Please change the line in your /etc/aliases file to make it look like:

|curl -F message=<- http://.../plog/moblog.php

That is, without the single quotes surrounding <-


  • If using the lightppd web server, you have to add the following parameter to the alias calling curl to make it actually POST the info to the web page, otherwise lighttpd just ignores the entire request, without even logging anything:
-H "Expect:"