Last active
December 31, 2015 05:09
-
-
Save ahomu/7938826 to your computer and use it in GitHub Desktop.
サンプルファイル ( filename の _ は / と脳内変換で )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AAPP_JSONProvider extends ACMS_APP | |
{ | |
public $version = '0.1'; | |
public $name = 'ACMS JSON Provider'; | |
public $author = 'mu.aho'; | |
public $desc = 'a-blog cms のデータをJSON APIとして扱うための拡張です'; | |
/** | |
* インストールする前の環境チェック処理 | |
* @return bool | |
*/ | |
public function checkRequirements() | |
{ | |
return true; | |
} | |
/** | |
* インストールするときの処理 | |
* データベーステーブルの初期化など | |
* @return void | |
*/ | |
public function install() { } | |
/** | |
* アンインストールするときの処理 | |
* データベーステーブルの始末など | |
* @return void | |
*/ | |
public function uninstall() { } | |
/** | |
* アップデートするときの処理 | |
* @return bool | |
*/ | |
public function update() { return true; } | |
/** | |
* 有効化するときの処理 | |
* @return bool | |
*/ | |
public function activate() { return true; } | |
/** | |
* 無効化するときの処理 | |
* @return bool | |
*/ | |
public function deactivate() { return true; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AAPP_JSONProvider_GET_Entries extends ACMS_GET | |
{ | |
var $_axis = array( | |
'bid' => 'self', | |
'cid' => 'self', | |
); | |
function get() | |
{ | |
$DB = DB::singleton(dsn()); | |
$SQL = SQL::newSelect('entry'); | |
$limit = !!LIMIT ? LIMIT : 10; | |
$page = !!PAGE ? PAGE : 1; | |
if ( $uid = intval($this->uid) ) { | |
$SQL->addWhereOpr('entry_user_id', $uid); | |
} | |
if ( empty($this->cid) and null !== $this->cid ) { | |
$SQL->addWhereOpr('entry_category_id', null); | |
} | |
if ( !empty($this->eid) ) { | |
$SQL->addWhereOpr('entry_id', $this->eid); | |
} | |
ACMS_Filter::entrySession($SQL); | |
ACMS_Filter::entrySpan($SQL, $this->start, $this->end); | |
if ( !empty($this->tags) ) { | |
ACMS_Filter::entryTag($SQL, $this->tags); | |
} | |
if ( !empty($this->keyword) ) { | |
ACMS_Filter::entryKeyword($SQL, $this->keyword); | |
} | |
if ( !empty($this->Field) ) { | |
ACMS_Filter::entryField($SQL, $this->Field); | |
} | |
$Amount = new SQL_Select($SQL); | |
$Amount->setSelect('*', 'entry_amount', null, 'count'); | |
if ( !$itemsAmount = intval($DB->query($Amount->get(dsn()), 'one')) ) { | |
return json_encode(array('entries' => array())); | |
} | |
ACMS_Filter::entryOrder($SQL, $this->order, $this->uid, $this->cid); | |
$from = ($page - 1) * $limit; | |
$limit = ((($from + $limit) > $itemsAmount) ? ($itemsAmount - $from) : $limit); | |
if ( 1 > $limit ) return ''; | |
$SQL->setLimit($limit, ($from)); | |
$q = $SQL->get(dsn()); | |
$rows = $DB->query($q, 'all'); | |
return json_encode(array('entries' => array_map(function($row) { | |
$row['entry_url'] = acmsLink(array( | |
'bid' => $row['entry_blog_id'], | |
'cid' => $row['entry_category_id'], | |
'eid' => $row['entry_id'] | |
), false); | |
return $row; | |
}, $rows))); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{callback}(<!-- BEGIN_MODULE Entries --><!-- END_MODULE Entries -->) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment