�ܻؤ�1�顪30�奵��꡼�ޥ�ܥ���������

����IT��Ȥ�Ư��30�奵��꡼�ޥ�Υ��饤�ߥ󥰵�Ͽ

2009ǯ10��

�ʤ󤫤��Τ����Ȥ������ʤΤǥ��ԥ��ѥ�⡣
jQuery��Ȥä�jsonp�ǥǡ���������
�Ȥꤢ�����饤�֥��ˤ��ƻȤ��Ȥ������ɤ߹��फ�󤸤ˡ�

bitlyApi.js

BitlyClient = function() {
  this._initialize();
}
$.extend(BitlyClient.prototype, {
  _initialize: function(login, apikey, version) {
    this.login = login || "LOGIN";
    this.apikey = apikey || "APIKEY";
    this.version = version || "2.0.1";
  },
  shorten: function(longUrl, target) {
    var result;
    $.ajax({
      type: "GET",
      url: "http://api.bit.ly/shorten",
      data: {
        "login": this.login,
        "apiKey": this.apikey,
        "version": this.version,
        "longUrl": longUrl
      },
      dataType: "jsonp",
      success: function(data) {
        for (var r in data.results) {
          result = data.results[r];
          break;
        };
        target.text(result.shortUrl);
      }
    });
  },
  expand: function(shortUrl, target) {
    var result;
    $.ajax({
      type: "GET",
      url: "http://api.bit.ly/expand",
      data: {
        "login": this.login,
        "apiKey": this.apikey,
        "version": this.version,
        "shortUrl": shortUrl
      },
      dataType: "jsonp",
      success: function(data) {
        for (var r in data.results) {
          result = data.results[r];
          break;
        };
        target.text(result.longUrl);
      }
    });
  }
});
var Bitly = new BitlyClient();


URL�ȥ������å��Ϥ��ƽ��Ϥ���饤�֥��ʤΤǻȤ����Ӥ˹�碌�ơ�
�Ȥꤢ����URL���Ϥ��ƽ��Ϥ����㡣

html

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></script>
<script src="bitlyApi.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
  $('input[id^=bitly]').click(function() {
    eval("Bitly."+$(this).val()+"($('input#url').val(), $('div#bitly-result'))");
  });
});
</script>
</head>
<body>
<input type="text" id="url" /><input type="button" value="shorten" id="bitly-shorten" /><input type="button" value="expand" id="bitly-expand" />
<div id="bitly-result"></div>

    ¤³¤Î¥¨¥ó¥È¥ê¡¼¤ò¤Ï¤Æ¤Ê¥Ö¥Ã¥¯¥Þ¡¼¥¯¤ËÄɲÃ

�ƥڡ����ˤ�ä��ɤ߹���js���Ѥ������Ȥ��ˡ�
��ñ�ʤ��Ȥ����ɡ��դ�˺�줽���ʤΤǡ�

/path/to/app/webroot/js/foo.js���ɤ߹��ߤ�����硣

��controller

����ȥ�����Ǥϥإ�ѡ��θƤӽФ���
<?php
class HogeController extends AppController {
  var $name = 'Hoge';
  var $helpers = array('Javascript');

  public function index() {
  }


��view

�ӥ塼�Ǥ�addScript��<head>������˵��Ҥ���롣
($scripts_for_layout����ʬ)
<?php $this->addScript($javascript->link('foo')); ?>

���ξ��˽��Ϥ��������Ϥ��Τޤ�
<?php echo $javascript->link('foo'); ?>

��layout

�쥤�����ȤϤȤꤢ��������ʤ��󤸤�$scripts_for_layout��񤯡�
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<?php echo $scripts_for_layout; ?>
</head>
<body>
    ¤³¤Î¥¨¥ó¥È¥ê¡¼¤ò¤Ï¤Æ¤Ê¥Ö¥Ã¥¯¥Þ¡¼¥¯¤ËÄɲÃ

�ɤ�Twitter��ڤ���٤�����
�ʤˤ��ڤ����Τ����ޤ����褯�狼���Τ�
��ʬ�Ƕ�̣�����Ƥ�褦��API�Ȥäƥ����Ⱥ��ޤ�����
����CakePHP���������ͤơ�

��������EC������ô���äݤ����ߤ����פ򥭡���ɤ˽���Ƥߤޤ�����

�Ȥꤢ�����֤äѤʤ����ߤǺ�ä��Τ���Ȥ��겡���ʴ����Ǥ���


����˾�ʤ���

Íß˾¤Ê¤¦

����å�����ä��ꡢ�⤦����äȥꥢ�륿��������������Ȳ�������¿������Ȼפ��ΤǤܤ��ܤ����ޤ���
    ¤³¤Î¥¨¥ó¥È¥ê¡¼¤ò¤Ï¤Æ¤Ê¥Ö¥Ã¥¯¥Þ¡¼¥¯¤ËÄɲÃ

�����livedoorBlog��AtomAPI������˰���³������֥����ä��㤦�����Ȼפä���ϥޤä���
Ʊ��AtomAPI����������Ʊ���ǹԤ���������Ȼפä���㤦�餷����

��������Ĵ�٤Ƥߤ��WSSEǧ�ڤ��ȼ��ݤ���
�Ǥ⤤����Ĵ�٤Ƥ�Ʊ���褦�˺��äƤ�ͤϤ��Ƥ⡢��褷�Ƥ�ͤ����Ĥ���ʤ�����

�ɵ����ݤ��ޤ�������(2010-02-03)  >>������ε����ء�



����ޤ�Ĵ�٤�livedoorBlog�Ȱ㤦�Ȼפ�����ʬ��pass_digest�κ�����ʬ��

livedoorBlog
$pass_digest = base64_encode(pack('H*', sha1($nonce.$created.$password)));

����֥�
$pass_digest = base64_encode(pack('H*', sha1($nonce.$created.strtoupper(md5($password)))));

�ѥ���ɤ�md5�������Ȥ���ʸ��������餷���Ȥξ���
�ǥޤ��ۥ�Ȥ��狼��ޤ��󡣡�

�֤äƤ���쥹�ݥ󥹤�
CurlResponse Object
(
    [body] => 
X-WSSE authentication required
    [headers] => Array
        (
            [Http-Version] => 1.1
            [Status-Code] => 401
            [Status] => 401 Unauthorized
            [Set-Cookie] => BIGipServerPool_comment=3395622060.20480.0000; expires=Sat, 17-Oct-2009 01:32:13 GMT; path=/
            [Date] => Fri, 16 Oct 2009 02:18:33 GMT
            [Server] => Apache
            [Content-Length] => 83
            [Content-Type] => application/x.atom+xml
        )

)

����������ʤ󤫰㤦�Ȥ��Ǵְ�äƤ�Τ���������
������Ѥ��������ɤϰʲ���

³�����ɤ�
    ¤³¤Î¥¨¥ó¥È¥ê¡¼¤ò¤Ï¤Æ¤Ê¥Ö¥Ã¥¯¥Þ¡¼¥¯¤ËÄɲÃ

app/vendors/shells/�ʲ��˥ե�����������

/path/to/app/vendors/shells/foo.php
<?php
class FooShell extends Shell {

  var $uses = array('Hoge');

  function bar(){
    $this->args[0]; /* ���ޥ�ɥ饤�󤫤�ΰ��� */
    /* ���� */
  }
}
?>


cron�ǻ��Ѥ��륱������¿���Ȼפ��Τǡ������Τ褦��-app��app�ǥ��쥯�ȥ�Υѥ������ꡣ
/path/to/cake/console/cake foo bar -app /path/to/app/
    ¤³¤Î¥¨¥ó¥È¥ê¡¼¤ò¤Ï¤Æ¤Ê¥Ö¥Ã¥¯¥Þ¡¼¥¯¤ËÄɲÃ

����ε����˰���³��AtomAPI�ѡ�
PHP��cURL���ѡ�

<?php
require_once 'cURL.php';

$atomapi_url = "http://cms.blog.livedoor.com/atom/";
$livedoor_id = "your livedoor id"; /* livedoorID */
$password = "your password"; /* �ѥ���� */
$category = "1"; /* ���ƥ��� */
$title = "sample"; /* ���������ȥ� */
$text = "content"; /* ������ʸ */

$created = date('Y-m-d\TH:i:s\Z');
$nonce = pack('H*', sha1(md5(time())));
$pass_digest = base64_encode(pack('H*', sha1($nonce.$created.$password)));
$wsse =
  'UsernameToken Username="'.$livedoor_id.'", '.
  'PasswordDigest="'.$pass_digest.'", '.
  'Nonce="'.base64_encode($nonce).'", '.
  'Created="'.$created.'"';

$text64= base64_encode($text);

$rawdata =
  '<?xml version="1.0"?>'.
  '<entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">'.
  '<title type="text/html" mode="escaped">'.$title.'</title>'.
  '<dc:subject type="text/html" mode="escaped">'.$category.'</dc:subject>'.
  '<content type="application/xhtml+xml" mode="base64">'.$text64.'</content>'.
  '</entry>';

$headers = array(
              "X-WSSE" => $wsse,
              "Content-Type" => "application/x.atom+xml",
              "Cache-Control" => "no-cache",
              );

$curl = new Curl();
$curl->headers = $headers;
$curl->options = array("POSTFIELDS" => $rawdata);
$res = $curl->post($atomapi_url);
?>
    ¤³¤Î¥¨¥ó¥È¥ê¡¼¤ò¤Ï¤Æ¤Ê¥Ö¥Ã¥¯¥Þ¡¼¥¯¤ËÄɲÃ

cakePHP��ȤäƤߤ롣
PHP����ե����2009������ε����ˤǤ���ѼԤ�����¿���ä��ե졼������
MVC�Υե졼�����Ȥä����Ȥ���ͤˤϤ狼��䤹���ǥ��쥯�ȥ깽����

�����ޤǤΥ���Ĥ�Ĥ顣

���ܹ�����post_types�ơ��֥�ξ���

����ȥ�����URL: ��ʣ����/post_types/�᥽�å�̾/�ѥ�᡼��
����ȥ����顧 ��ʣ����PostTypesController (extends AppController)
��ǥ롧 ��ñ����PostType��(extends AppModel)
�ӥ塼�� ��ʣ����app/views/post_types/�ƥ᥽�å�.ctp

��ǥ�

  • �ơ��֥�μ祭���ϡ�"id"�Ȥ����ե�����ɤǡ�primary��auto_increment �Ǻ��Τ����ܡ�
  • "��ǥ�̾_id"�Ȥ����ե�����ɤ�������ǡ�¾�Υơ��֥��ǥ�ؤγ��������Ȥ������ꡣ �㡧users �ơ��֥����ˡ� "post_id" ����������͡�posts �ơ��֥�� id �ò»²¾È¡ï¿½ "post_type_id" ��������� post_types �ơ��֥�� id �ò»²¾È¡ï¿½
  • "created" (DATETIME)�Ȥ����ե�����ɤ������������ǡ��������ǡ���������Ȼ��֤���ưŪ�˵�Ͽ��
  • "modified" (DATETIME)�Ȥ����ե�����ɤ������������ǡ��ǡ�������������뤿�Ӥ˻��֤���ưŪ�˵�Ͽ��
  • "updated" (DATETIME)�Ȥ����ե�����ɤ������������ǡ��ǡ�������������뤿�Ӥ˻��֤���ưŪ�˵�Ͽ��
  • "title"�Ȥ����ե�����ɤ���ȡ����Υڡ�����ɸ��Υ����ȥ�̾�Ȥ������Ѥ���롣
  • "name"��"title" �Ȥ����ե�����ɤ���ȡ��������黲�Ȥ��줿���ˡʻ��꤬�ʤ���Сˤ����ͤ����쥯�ȥܥå����ʤɤΡ��������̾�פȤ��Ƽ�ưŪ�����Ѥ���롣(����������ȡ�generateList()�ΰ��������ꤵ��Ƥ��ʤ����ˤϤ��Τ褦��ư���Ȥ������Ȥˤʤ�ޤ���)�ɤ����ʤ���С�id���ͤ�����ǥå����ȹ���̾��ξ��������ޤ����ʤ��Τ�����ν����ϡ�model_php4.php�� model_php5.php �˽ñ¤«¤ï¿½Æ¤ï¿½ï¿½Þ¤ï¿½ï¿½ï¿½ï¿½ï¿½

�ӥ塼����Ϥ���ɬ�פ��ʤ��᥽�åɤξ��

<?php
$this->autoRender = false;
?>
���졢���Хơ��֥�ɬ�פʤΡ����������äƻפäƤ��ޤä����� ������⡣

�ơ��֥�̤���ѥ�ǥ롢��ǥ�̤���ѥ���ȥ�����

��DB����Ѥ��ʤ���ǥ��$useTable = false;
����ǥ����Ѥ��ʤ�����ȥ������ var $uses = array();���ޤ��� var $uses = null��OK��
    ¤³¤Î¥¨¥ó¥È¥ê¡¼¤ò¤Ï¤Æ¤Ê¥Ö¥Ã¥¯¥Þ¡¼¥¯¤ËÄɲÃ

¤³¤Î¥Ú¡¼¥¸¤Î¥È¥Ã¥×¥Ø

'); label.html('\ �饤�֥ɥ��֥����ǤϹ���Υѡ����ʥ饤�������¬��Τ��᥯�å���(cookie)����Ѥ��Ƥ��ޤ���
\ ���ΥХʡ����Ĥ��뤫�������³���뤳�Ȥǥ��å����λ��Ѥ�ǧ������������ΤȤ����Ƥ��������ޤ���
\ �ޤ��������ͤ����ҥѡ��ȥʡ���Ȥˤ��������μ�³���ˤ�ꡢ���å����λ��Ѥ�������뤳�Ȥ�Ǥ��ޤ���
\ �ܺ٤��饤�֥ɥ����ѵ���򤴳�ǧ����������\ '); banner.append(label); var closeButton = $('