$news_id = $query('news_id'); $title = trim($query('title')); $abstract = trim($query('abstract')); $pub_time = $query('pub_time'); $thumbnail = $query('thumbnail'); $errors = array(10 => 'Invalid Arguments', 50 => 'Add article failed'); try { if (empty($site) || empty($news_id) || empty($title) || empty($pub_time)) { _log("params error in addArticle site:{$site}, {$news_id}, {$news_id}, title:{$title}", "ERROR"); throw new CmsInterfaceException(10); } $controller = $prj->rs->data->ext['tags']; $db = $prj->CData->CDb->w; WF_Registry::set('db', $db); $title = project_convert_input($prj, $title); $abstract = project_convert_input($prj, strval($abstract)); $result = $controller->addArticle($site, $news_id, $title, $pub_time, $abstract, $thumbnail); if ($result === false) { throw new CmsInterfaceException(50); } $cost = microtime(true) - $profile_begin; $prj->fw->interface->out(0, 'success', $cost, $result); } catch (CmsInterfaceException $e) { project_output_error($prj, $e, $errors); } catch (Exception $e) { $this->fw->interface->out($e->getCode(), $e->getMessage(), '', ''); } function _log($msg, $level = 'ERROR') { global $prj; $prj->CLog->w($level, $msg);
require_once 'inc/tags/interface.inc.php'; require_once 'inc/tags/tags.inc.php'; $prj = new Tags_Project('tcms.interface.tags'); project_init_params($prj); $len = io_get('len'); #$category_id = io_get('c'); $keywords_str = trim(io_get('keywords')); $input = io_get('input'); $errmsgs = array(10 => '关键词为空哦亲', 50 => '接口调用出错啦'); try { if (empty($keywords_str)) { throw new CmsInterfaceException(10); _log('输入关键词为空', 'DEBUG'); } $len = $len > 0 ? $len : 20; $prefix = project_convert_input($prj, $keywords_str); $controller = $prj->rs->data->ext['tags']; $db = $prj->CData->CDb->r; WF_Registry::set('db', $db); $keywords = explode(';', $keywords_str); $tags = $controller->suggestByKeywords($keywords); if (!is_array($tags)) { throw new CmsInterfaceException(50); _log("suggest 接口调用出错"); } $data = project_convert_output($prj, $tags); $prj->fw->interface->out(0, 'success', '', $data); } catch (CmsInterfaceException $e) { project_output_error($prj, $e, $msgs); } catch (Exception $e) { $this->fw->interface->out($e->getCode(), $e->getMessage(), '', '');
$site = $query('site'); $id = $query('id'); $tags_str = trim($query('tags')); $errors = array(10 => '参数错误: site或Id未提供', 11 => '参数错误:未指定标签', 90 => '处理错误: 设定标签失败'); try { if (empty($site) || empty($id)) { throw new CmsInterfaceException(10); _log("参数错误 site:{$site};id:{$id};tags_str:{$tags_str}", 'DEBUG'); } if (empty($tags_str)) { throw new CmsInterfaceException(11); _log("未指定标签, site:{$site};id:{$id}", 'DEBUG'); } //过滤输入, 转义输出 $tags_str = strip_tags($tags_str); $tags_str = project_convert_input($prj, $tags_str); $tags = ArticleTags::model()->str2arr($tags_str); $controller = $prj->rs->data->ext['tags']; $db = $prj->CData->CDb->w; WF_Registry::set('db', $db); $result = $controller->setNewsTags($site, $id, $tags); if (!$result) { throw new CmsInterfaceException(90); _log("标签设定失败, site:{$site}; id:{$id}; tags:{$tags_str}", 'ERROR'); } $prj->fw->interface->out(0, 'success', '', true); } catch (CmsInterfaceException $e) { project_output_error($prj, $e, $errors); } catch (Exception $e) { $this->fw->interface->out($e->getCode(), $e->getMessage(), '', ''); }
require_once 'inc/tags/interface.inc.php'; require_once 'inc/tags/tags.inc.php'; $prj = new Tags_Project('tcms.interface.tags'); project_init_params($prj); $len = io_get('len'); #$category_id = io_get('c'); $keywords_str = io_get('keywords'); $input = io_get('input'); $errors = array(10 => '查询为空', 50 => '接口调用出错'); try { if (empty($input)) { throw new CmsInterfaceException(10); _log('输入前缀为空', 'DEBUG'); } $len = $len > 0 ? $len : 20; $prefix = project_convert_input($prj, $input); $controller = $prj->rs->data->ext['tags']; $db = $prj->CData->CDb->r; WF_Registry::set('db', $db); $tags = $controller->suggestByInput($input); if (!is_array($tags)) { throw new CmsInterfaceException(50); _log("suggest 接口调用出错"); } $data = project_convert_output($prj, $tags); $prj->fw->interface->out(0, 'success', '', $data); } catch (CmsInterfaceException $e) { project_output_error($prj, $e, $errors); } catch (Exception $e) { $this->fw->interface->out($e->getCode(), $e->getMessage(), '', ''); }