/** * 页面渲染 */ function render($layout = NULL, $data = NULL, $termination = true) { if ($layout == NULL) { send_result(0, "html template dose not exist"); } $layout_file = AROOT . 'view/' . $layout . '.tpl.html'; if (file_exists($layout_file)) { @extract($data); require $layout_file; if ($termination) { die; } } else { send_result(0, "html template dose not exist"); } }
if ($service->update($id, v('title'), v('abstract'), v('content'), v('cid'), v('type'))) { if ($service->publish($id)) { // 静态化文章,及更新列表 $service->staticArticle($id); $category = $categoryService->findById(v('cid')); $service->staticArticleList($category); $service->staticIndex(); } } } else { if ($service->save(v('title'), v('abstract'), v('content'), v('cid'), v('type'))) { $id = last_id(); if ($service->publish($id)) { // 静态化文章,及更新列表 $service->staticArticle($id); $category = $categoryService->findById(v('cid')); $service->staticArticleList($category); $service->staticIndex(); } } } forward('article_list.php'); } else { send_result(0, 'request does not have title,abstract,content,id,cid parames'); } } } } } send_result(0, "request does not have correct method parame");
<?php include '..' . DIRECTORY_SEPARATOR . 'init.php'; include SROOT . 'articleService.class.php'; $article_service = new ArticleService(); $article_list = $article_service->getAll(ARTICLE_PUBLISH, v('cid') ? v('cid') : null, v('page') ? v('page') : null); if ($article_list) { send_result(1, $article_list); } else { send_result(0, 'empty data'); }
/* call a class with a static 'load' method and the given normal method */ /* call a class with a static 'load' method and the given normal method */ case 2: if (!$id_to_load) { throw new Error(503, 'Missing "id" parameter in order to call static method "load" of class ' . $class_to_call); } $object = $class_to_call::load($id_to_load); $result = $object->{$method_to_call}($params); break; /* call the given normal method */ /* call the given normal method */ default: $object = new $class_to_call(); $result = $object->{$method_to_call}($params); } send_result($result); send_log('end of server process'); echo json_encode($global_result); } catch (Error $e) { if (!headers_sent()) { header('HTTP/1.0 ' . $e->http_code . ' ' . $e->http_status, TRUE, $e->http_code); } send_log('Backtrace: ' . $e->getTraceAsString()); send_error($e->getMessage()); echo json_encode($global_result); } catch (Exception $e) { if (!headers_sent()) { header('HTTP/1.0 500 Internal Server Error', TRUE, 500); header('Content-type: text/plain', TRUE); } echo 'Exception:' . TUNA_NEWLINE . $e->getMessage() . TUNA_NEWLINE . TUNA_NEWLINE;
/** * Demo接口 * @ApiDescription(section="Demo", description="乘法接口") * @ApiLazyRoute(uri="/demo/times",method="GET") * @ApiParams(name="first", type="string", nullable=false, description="first", check="check_not_empty", cnname="第一个数") * @ApiParams(name="second", type="string", nullable=false, description="second", check="check_not_empty", cnname="第二个数") * @ApiReturn(type="object", sample="{'code': 0,'message': 'success'}") */ public function demo($first, $second) { return send_result(intval($first) * intval($second)); }
/** * 默认提示 * @ApiDescription(section="Demo", description="默认提示") * @ApiLazyRoute(uri="/about/contact",method="GET") * @ApiReturn(type="object", sample="{'code': 0,'message': 'success'}") */ public function contact() { $data = array('background' => 'aboutus/contact.jpg', 'title' => 'Contact Us', 'location' => 'About Us / Contact Us'); return send_result($data); }
<?php include '..' . DIRECTORY_SEPARATOR . 'init.php'; include SROOT . 'articleService.class.php'; $service = new ArticleService(); if (v('id')) { $data = $service->findById(v('id')); render($GLOBALS['config']['article']['detail_template'], $data); } else { send_result(0, 'request does not have id parames'); }
function send_failure($term) { $xml = '<?xml version="1.0"?><api><parse><text xml:space="preserve">'; $xml .= htmlspecialchars('<h3 align="center">', ENT_QUOTES) . get_int_text("wiki_fail", array($term)) . htmlspecialchars('</h3>', ENT_QUOTES); $xml .= '</text></parse>'; $xml .= '<rompr><domain>null</domain><page>null</page></rompr></api>'; send_result($xml); }
function send_error($code, $message) { header("HTTP/1.0 500 Application Error"); send_result($code, $message); }
function apido() { if (!isset($_REQUEST['request']) || !($request = unserialize($_REQUEST['request']))) { return send_error(ARGS_ERROR, 'request can\'t empty'); } $source = $request['source']; if (strlen($source) < 1) { return send_error(ARGS_ERROR, 'source can\'t empty'); } if (!isset($GLOBALS['config']['whois'][$source]) || strlen($GLOBALS['config']['whois'][$source]) < 1) { return send_error(ARGS_ERROR, 'bad source id'); } $data = $request['data']; if (strlen($data) < 1) { return send_error(ARGS_ERROR, 'data can\'t empty'); } $ckeys = z(t($request['ckeys'])); if (strlen($ckeys) < 1) { $ckey_array = array("everything"); } else { $ckey_array = array("everything"); $keys = explode(',', $ckeys); if (is_array($keys)) { $ckey_array = array_merge($keys, $ckey_array); } } $action = v('action'); if (strlen($action) < 1) { $action = "display"; } $timeline = date("Y-m-d H:i:s"); // create channel $channel = new SaeChannel(); $mc = memcache_init(); $channel_name = 'nowboard-url-all'; if ($action == 'display') { $data = z(t($data)); } if ($url = $mc->get($channel_name)) { foreach ($ckey_array as $ckey) { $message = array('ckey' => $ckey, 'data' => $data, 'action' => $action, 'timeline' => $timeline, 'source' => $GLOBALS['config']['whois'][$source]); $channel->sendMessage($channel_name, json_encode($message)); } } /* if( is_array(c('talkman')) ) { foreach( c('talkman') as $uid ) { $channel_name = 'nowboard-url-'.$uid; if( $action == 'display' ) $data = z(t($data)); if( $url = $mc->get($channel_name) ) { foreach( $ckey_array as $ckey ) { $message = array( 'ckey' => $ckey , 'data' => $data , 'action' => $action , 'timeline' => $timeline , 'source' => $GLOBALS['config']['whois'][$source] ); $channel->sendMessage( $channel_name , json_encode($message) ); } } } } */ return send_result('send data to * # ' . $ckeys . ' from ' . $GLOBALS['config']['whois'][$source]); }