ܻؤ1顪30奵꡼ޥܥ

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

ƥꡧ PHP

WebѴӥϤ󤢤ɡѴƽϤѥϤޤ긡ˤäʤäΤǥ⡣

OSCentOS6
OpenOfficeJODConverter򥤥󥹥ȡ롣
Τεȡ

OpenOffice.orgɥѴġȤƳѤˡ
JODConverter
OpenOfficeȤäPDF

# export DISPLAY=:1.0
# Xvfb :1 &
# Xvfb :1 -screen 0 1024x768x8
# soffice -headless -accept="socket,port=8100;urp;" -nofirststartwizard &
# netstat -anp | grep 8100
# java -jar /path/to/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar /tmp/sample.docx /tmp/sample.pdf


    Υȥ꡼ϤƤʥ֥åޡɲ

ǶȤ빽html쥤ԥ󥰤뤳Ȥ¿Τǥ⡣
ǽϤƤɡȤäƤΤϣѥ
٥ޡȤäƺ®äȤʤñ˴줫⡣

scrape_func.php

Υ饤꡼ܤΥץ륳ɤ˴ޤޤƤե롣
http://www.oreilly.co.jp/books/4873111870/download.html
Ƚ񤤤ľŪ˼äƤ롣
$_rawData = getURL($url);
$_rawData = mb_convert_encoding($_rawData, "UTF-8", "auto");
$_rawData = cleanString( $_rawData );

$headline = getBlock("<div id=\"headline\">","</div>",$_rawData,false);

$title = getElement("h1", $_rawData);

XPATH

xpathȤΤŪȤϻפɡä㤤Ⱦ˵󤲤饤֥ᤤ͡
Ǥ˸¤餺Ȥ뤫
Υ֥Υȥ㡣
$res = file_get_contents($url);
$dom = @DOMDocument::loadHTML($res);
$xml = simplexml_import_dom($dom);

//ǿΥȥ
$title = $xml->xpath("//div[@class='hentry']/h2/a/text()");
echo (string) current($title);

//3ܤεΥȥ
$title = $xml->xpath("//div[@class='hentry'][3]/h2/a/text()");
echo (string) current($title);
//3ܤεΥ
$link = $xml->xpath("//div[@class='hentry'][3]/h2/a/@href")

쥤ԥ󥰤äƻʺȤ͡
ƥȤȤˤܼۤưб
    Υȥ꡼ϤƤʥ֥åޡɲ

GoogleMapsAPIȤνƤäꤹ롣
֥롼ݥʤȤ˻Ȥޤ
ñAPIáƤʤΤǥ٤ˡ

ε CakePHP۰־μȡ2֤εΥ׻ΥݡͥȤɲä⡣

Ȥ櫓ǡ

App/controllers/components/geo.php

class GeoComponent extends Object {
  public function addr2geo($addr=""){
    $url = sprintf("http://maps.google.co.jp/maps/geo?q=%s&output=json&key=%s",
                   urlencode($addr),
                   'GoogleMapsAPIKEY');
    $res = file_get_contents($url);
    $data = json_decode($res);
    $geo = $data->Placemark[0]->Point->coordinates;
    return array('lng' => $geo[0], 'lat' => $geo[1]);
  }
}
ǡǤʤäȤνӽ񤤤Ƥ͡

App/controllers/foo_controller.php

class FooController extends Controller {
  var $name = 'Foo';
  var $components = array('Geo');

  function index () {
    $addr = 'Կɶ迷ɻ38-1';
    $geo = $this->Geo->addr2geo($addr);
    echo $geo['lat']; //
    echo $geo['lng']; //
  }
}


־򥵡ӥ˻ȤȤ⤷͡
⤤äƤФʡ
    Υȥ꡼ϤƤʥ֥åޡɲ

20100630211430 褯ꤽʤʤ󤸤Υ̡
󤿤ܥȡID/PASSϤեࡣ

󤿤ϤޤɡȤꤢϿޤ
ꥢΥȥIP¤Ϥޤ礦äƤ󤸡


ɸAuthݡͥȤȡktai饤֥ȤäƤޤ

UIDꤷƤС֤󤿤פǤơƤʤID/PASSϤUIDꤹ뤳ȤǤȤǽ
ϥȥåץڡǹԤǤ
CakeΥС1.3

APP/controllers/top_controller.php

class TopController extends AppController
{
  var $name = 'Top';
  var $uses = 'User';
  var $helpers = array('Ktai','Session','Form');
  var $components = array('Ktai','Session','Auth');

  function beforeFilter() {
    $this->Auth->loginAction = '/';
    $this->Auth->autoRedirect = false;
    $this->Auth->authorize = 'controller';
    $this->Auth->allow('index');
    parent::beforeFilter();
  }

  function beforeRender() {
    parent::beforeRender();
  }

  function index () {
    if ($user = $this->Auth->user()) {
      if (isset($this->data['add_uid'])) {
        $user['User']['uid'] = $this->Ktai->get_uid();
        $this->User->save($user['User']);
/* 7/14ɵ */
        $user = $this->User->findById($set['id']);
        $this->Auth->login($user);
/* 7/14ɵޤ */
      }
      $this->redirect($this->Auth->redirect());
    } else {
      if (isset($this->data['auto_login'])) {
        if ($user = $this->User->findByUid($this->Ktai->get_uid())) {
          if ($this->Auth->login($user['User'])) {
            $this->redirect($this->Auth->redirect());
          } else {
            $this->Session->setFlash('٤󤿤򤷤Ƥ',null);
          }
        } else {
          $this->Session->setFlash('󤿤꤬Ƥޤ',null);
        }
      }
    }
  }

  function isAuthorized () {
    $user = $this->Auth->user();
    $user['User']['last_login'] = date('Y-m-d H:i:s');
    $this->User->save($user['User']);

    return true;
  }
}

äƤ뤳Ȥϰʲ3
ID/PASSǥơ֤󤿤ꤹפ˥åƤСUIDȤäƥơ֥ͤùࡣ
󤿤ξUID򥭡usersơ֥뤫ǡäƤAuth->loginͤùǥ󤵤롣
isAuthorized()ǥ򹹿

usersơ֥

+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| id          | int(10)      | NO   | PRI | NULL    | auto_increment |
| username    | varchar(100) | NO   |     | NULL    |                |
| password    | varchar(100) | NO   |     | NULL    |                |
| uid         | varchar(100) | NO   |     | NULL    |                |
| flag        | int(1)       | NO   |     | NULL    |                |
| last_login  | datetime     | NO   |     | NULL    |                |
| created     | datetime     | NO   |     | NULL    |                |
| updated     | datetime     | NO   |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+


åȤʤӤޤޤ󤢤뤿ʼdocomoˡΤ˺ʤ褦˥⡣

APP/config/bootstrap.php

if (!isset($_SESSION)) {
  if ($ini_set) {
    ini_set('session.use_trans_sid', 1);
    ini_set('session.serialize_handler', 'php');
    ini_set('session.use_cookies', 0);
  }
}


2010/07/14ɵ
κݤUIDơ֥ɲä硢
$this->Auth->user()Ǽ桼ǡϥåʤΤǺ٥󤷤ʤȤʤߤ
    Υȥ꡼ϤƤʥ֥åޡɲ

ơ֥ΥΥפtinyint(1)ˤơsave褦Ȥͤ

  $set = array('type' => 2);
  $this->Data->create();
  $this->Data->save($set);

type2褦ȤƤɡǡ١Ƥߤ1ˤʤäƤ롪
ä餤äѤǤƤΤǡߤʤäѤϥޤ͡
ʤߤCakePHP1.3Ǥ

Cakephptinyintbooleanˤ餷ʤƤä

CORE/libs/model/datasources/dbo/dbo_mysql.php line474
    if (($col == 'tinyint' && $limit == 1) || $col == 'boolean') {
      return 'boolean';
    }

ϼºθƤߤʤȵŤʤ͡
̵̤˻֤Ȥ줿
    Υȥ꡼ϤƤʥ֥åޡɲ

־

־򰷤饤֥ϤȤޤ
docomoiꥢǡѤ֤̾Ƥޤ
http://labs.unoh.net/2008/08/phpgeomobilejp_converter.html
vendors/Geomobilejp/ˤĤäࡣ

2֤ΰٷ٤ľΥ

򻲹͡
http://www.pahoo.org/e-soul/webtech/php02/php02-21-01.shtm
嵭Υ饤֥Υǡ򤽤Τޤͤù褦ˡäȤ
׻ʬϤΤޤޤǤ


ǡCakePHPΥݡͥȤǻȤäΤǤޤȤޤ
³ɤ
    Υȥ꡼ϤƤʥ֥åޡɲ

ΤǻȤȤХURLȤ
Ķˤäڤؤʤȡ

֡ȯɤǤȤΤ
APP/config/common.php

Ķ˰¸Τ
dev.phpproduction.php
ߤʤ󤸤ˡ

ĶꤹΤ
apacheconfvirtualHost񤤤Ƥ褦ʤȤ
CAKE_CONFIGŪ̾ǡ

SetEnv CAKE_CONFIG dev

APP/controller/app_controller.php

configꤷ
ǡbeforeRendeerconfig˥åȤ
viewǤ$configǻȤ褦ˡ

  function beforeFilter() {
    Configure::load('common');
    if (isset($_SERVER['CAKE_CONFIG'])) {
      Configure::load($_SERVER['CAKE_CONFIG']);
      $this->config = array_merge(Configure::read("common"), Configure::read($_SERVER['CAKE_CONFIG'\
]));
    } else {
      $this->config = Configure::read("common");
    }
  }
  function beforeRender() {
    $this->set("config", $this->config);
  }
    Υȥ꡼ϤƤʥ֥åޡɲ

zoomeư򥿥Ǹ

ǶΥưϤäѤzoomeǤ͡
̥礭̤礭ӥåȥ졼Ȥ⤤
˥ưήƤƤ褦˻פޤ
Ȥ櫓ǡzoomeΥPHPǡ

require_once 'XML/RPC.php';

$arr = array('tagname' => '',
             'offset' => 0,
             'length' => 10
             );
$params  = new XML_RPC_Value(array(
                                   'tagname' => new XML_RPC_Value($arr['tagname'], 'string'),
                                   'offset' => new XML_RPC_Value($arr['offset'], 'i4'),
                                   'length' => new XML_RPC_Value($arr['length'], 'i4'),
                                   ), "struct");

$msg = new XML_RPC_Message('zoome.tagSearch', array($params));
$cli = new XML_RPC_Client('/xmlrpc', 'up.zoome.jp', 80);
$res = $cli->send($msg);

if (!$res->faultCode()) {
  $data = XML_RPC_decode($res->value());
  /* "Total:". $data['count']; */
  foreach($data['list'] as $key => $val) {
    $zoome = array(
                   'zoomeid' => $val['zoomeid'],
                   'diaryid' => $val['diaryid'],
                   'title' => $val['title'],
                   'url' => $val['diaryurl'],
                   'body' => $val['body'],
                   );
  }
} else {
  exit('CODE:'.$res->faultCode(). ':'. $res->faultString());
}


ߤ򤤤ХȤۤǤ͡
ǥեȤǿȻפǤɡΥȤ餤Ϥۤʡ
¾ˤƤȤΥ᥽åɤΤǸɥȤ򻲾ȤƤߤƤ

͡zoome API(XML-RPC)ɥ
    Υȥ꡼ϤƤʥ֥åޡɲ

OpenIDǥ󤷤ơ˥å͡ϿƤ餦褦ʲ̤ǤΥХǡȥ⡣

usersơ֥nickname˥ХǡȤ򤫤


åܤ3ġ

  • ˡʥ˥å͡फ
  • ʸ⤫
  • ΤߤǤϤʤ

ΤߤϤfunction notSpaceǥå

APP/model/user.php

<?php
class User extends AppModel {
    var $name = 'User';
    var $validate = array(
        'nickname' => array(
                            'notSpace' => array(
                                                'rule' => array('notSpace'),
                                                'message' => 'ΤߤϿǤޤ'
                                                ),
                            'between' => array(
                                               'rule' => array('between', 1, 45),
                                               'message' => '1ʸʾϤƤ15ʸޤǡ'
                                               ),
                            'isUnique' => array(
                                                'rule' => 'isUnique',
                                                'message' => 'ǤϿƤޤ'
                                                ),
                            ),
        );
    function notSpace($field=array()) {
      foreach($field as $name => $value){
        if (preg_match("/^( |)+$/", $value)) {
          return false;
        } else {
          return true;
        }
      }
    }
}
?>
    Υȥ꡼ϤƤʥ֥åޡɲ

ʥ֥AtomAPIݤʤε
ϸƤäѤƱ褦˺äƤͤߤ

Ȥ櫓ǡפ֤Ĵľ
ΥȰ㤦ʬԥååס
äѤWSSEǧݥȤǤ줵̤ФȤϤʤꡣ


$nonce = sha1(md5(time()));


ʸ鲿Ǥ⤤Ȥϻפɡ


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


դä
ʸˤ󤸤ʤʸˤ롣


Ȥgetǵη̤postURLȤäƵꤲߤ

Ѥ
³ɤ
    Υȥ꡼ϤƤʥ֥åޡɲ

ȤꤢƥȤǥХ륵ȤǺäƤߤ褦ȡ
¸ΤܤƤ륵ȡʥͥȥˤΥХǺäƤߤ

Ȥ˥ХѤ˵ǽɲäʤɤϤƤ餺
ǥ꡼ä󥭥󥰤ñ̤ˤɽ餤
PCǤZendFrameworkǺäƤ뤱ɡХǤCakePHPäƤȤʰ㤤

2010ǯ118PCȤǥХǤιΡ
1֤η¬

Х


moPV

moUU



Ʊ֤PCǡ


pcPV

pcUU



ͻ


UUߤȡΤޤޤǤPCǤ1/10餤Υ桼褽ʴ
ޡǤ⡢ΥȤ9᤯Υ桼ͥȥ򥿤ʤΤPCȤȤ⤤äƤȤ
΢̤ǥå뤳Ȥ¿
Ĥ1ΥꥢʾСˤưȤ˸Ƥäƹͤȡη̤Ǽ

褯ȥХǤPV1/231/24ȤǤ롣


פ˳ˤϽФˡȤǤäȥͥȥäƤѥ͡


ʤ󤫤ޤǹͻ˳οƤäƤʤʤʤ͡
    Υȥ꡼ϤƤʥ֥åޡɲ

˰³GoogleAnalyticsƳ
ľܽ񤤤Ƥ⤤ɡȤꤢإѡͤù󤿡
vendorˤΤޤޤۤΤʡ

APP/views/helpers/ga.php

Υץ륽إѡѤ˽񤭴

<?php
class GaHelper extends Helper {
  private $GA_ACCOUNT="MO-XXXXXX-X";
  private $GA_PIXEL="/ga.php";

  function getUrl() {
    $url = "";
    $url .= $this->GA_PIXEL . "?";
    $url .= "utmac=" . $this->GA_ACCOUNT;
    $url .= "&utmn=" . rand(0, 0x7fffffff);
    $referer = isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : '';
    $query = $_SERVER["QUERY_STRING"];
    $path = $_SERVER["REQUEST_URI"];
    if (empty($referer)) {
      $referer = "-";
    }

    $url .= "&utmr=" . urlencode($referer);
    if (!empty($path)) {
      $url .= "&utmp=" . urlencode($path);
    }
    $url .= "&guid=ON";
    return str_replace("&", "&", $url);
  }
}
?>

APP/controllers/app_controller.php

٤ƤΥڡǽФ顢app_controller

<?php
class AppController extends Controller {
  var $helpers = array('ga');

APP/views/layouts/main.ctp

ᥤΥ쥤Ȥbody˽񤯡

<html>
<head></head>
<body>
   
   
<?php $googleAnalyticsImageUrl = $ga->getUrl(); ?>
<img src="<?php echo $googleAnalyticsImageUrl; ?>" />
</body>
</html>

APP/webroot/ga.php

ȤGAδ̤DLǤga.phpwebroot֤ƽλ
ưƤߤ

    Υȥ꡼ϤƤʥ֥åޡɲ

xml

<?xml version="1.0" encoding="Shift_JIS"?>

ǽ񤯤ȥ顼ˤʤ롣
֤ߤʺǽˤǤĤޤŤ͡
ä餹ǤƤ

ˡϤĤäơ
echoǤ
apache
Ȥ

echoǽФޤ
<?php echo'<?xml version="1.0" encoding="Shift_JIS"?>'."\n"; ?>

DOCTYPEλ

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">

3ꥢ̤DOCTYPEʬΥ
http://ma-san.org/2009/10/htmlphpdoctype.html

Content-Typeإåλ

<meta http-equiv="Content-Type" content="application/xhtml+xml ; charset=Shift_JIS" />

apacheǤǤϤʤ󻪤ȤŪˤ褦˥ˡ
app_controller.phpbeforerenderǽϡ
*)Ѿbeforerender()parent:beforerender()˺줺ˡ

APP/controller/app_controller.php

<?php
class AppController extends Controller {
  function beforerender() {
    header('Content-Type: application/xhtml+xml');
  }
}

ߥ졼

docomo
http://www.nttdocomo.co.jp/service/imode/make/content/browser/html/tool2/index.html

softbank
http://creation.mb.softbank.jp/web/web_tool.html

au
http://www.au.kddi.com/ezfactory/tool/ue/
http://web.archive.org/web/*/developer.openwave.com/ja/tools_and_sdk/openwave_mobile_sdk/SDK62K/Openwave_SDK_62K.exe

fireMobileSimulator
http://firemobilesimulator.org/
    Υȥ꡼ϤƤʥ֥åޡɲ

äĴ٤뤳ȤäΤǡȤƻĤƤޤ

ܸtweetˡϤȤ⤦ɡ
ϥեAPIǥ桼κǿΥơ뤳Ȥ顢
ͭ̾ͤΥեtweet򽸤ʿͤФƤߤ褦ȡ

֤׳ŪˤɤΤ餤tweetʿͤȤפȤƿѤǤͤȤäƤϤ͡
ä褦ʽʤä褦ʵ뤱ɡȤꤢŬʿȤäƤߤޤ

åȤȤͭ̾ͤϾ֤
֤ΥեAPIǼʿͤޤ

äȸŤAPIλ͸Ƥpage=1Ȥǥڡꤹäƽ񤤤ƤɡΥɥȸcursorˤʤäƤ
̵̤˥ϥޤä

ͤcursor=-1ꤷơ쥹ݥ󥹤next_cursor֤äƤΤǼΥڡ򸫤ȤϤͤꤹ롣
פcursor=1,2,3Ȥʤߤ

˽񤤤ƤñʥХåäƤߤȤ
оTweet6587tweet
ȡʸ234153ʸ
ʿTweetʸ35.5ʸ
ʾΤ褦ʷ̤ˡ
*)RTǻϤޤäƤtweetϽޤ

٤äƤߤƤ30ʸäΤǡ
ܿͤ3040ʸǤĤ֤䤤ƤǤ礦֤

tweetLength.php

<?php
$username = "USERNAME";
$password = "PASSWORD";
$target = 'kazuyo_k';

$tweet=0;
$length=0;
$cursor = -1;
for ($i=0;$i<150;$i++) {
  if ($cursor == 0) break 1;

  $url = sprintf("http://twitter.com/statuses/followers.json?cursor=%d&screen_name=%s",$cursor,$target);
  $json = request($url,$username,$password);
  if (!is_array($json->users)) continue 1;
  foreach ($json->users as $key => $val) {
    if(isset($val->status)) {
      //RTǻϤޤtweetФ
      if(preg_match("/^RT(.+)/",$val->status->text)) continue 1;

      if (mb_detect_encoding($val->status->text) != 'UTF-8') continue 1;
      $tweet++;
      $length+=mb_strlen($val->status->text, 'utf-8');
    }
  }
  $cursor = $json->next_cursor;
}
echo "tweet  : " . $tweet . "\n";
echo "length : " . $length . "\n";
echo "avg    : " . $length / $tweet . "\n";

function request($host='',$username='',$password=''){
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $host);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
  curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  $result = curl_exec($ch);
  curl_close($ch);

  return json_decode($result);
}
?>
    Υȥ꡼ϤƤʥ֥åޡɲ

ƥڡˤäɤ߹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
    Υȥ꡼ϤƤʥ֥åޡɲ

ΥڡΥȥåץ