ܻؤ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ôäݤߤפ򥭡ɤ˽Ƥߤޤ

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


˾ʤ

˾ʤ

åäꡢ⤦äȥꥢ륿Ȳ¿ȻפΤǤܤܤޤ
    Υȥ꡼ϤƤʥ֥åޡɲ

livedoorBlogAtomAPI˰³֥ä㤦Ȼפäϥޤä
Ʊ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ǻѤ륱¿ȻפΤǡΤ褦-appappǥ쥯ȥΥѥꡣ
/path/to/cake/console/cake foo bar -app /path/to/app/
    Υȥ꡼ϤƤʥ֥åޡɲ

ε˰³AtomAPIѡ
PHPcURLѡ

<?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"Ȥեɤǡprimaryauto_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 = nullOK
    Υȥ꡼ϤƤʥ֥åޡɲ

ΥڡΥȥåץ