Example #1
0
<?php

require_once 'header/web.inc.php';
require_once 'inc/tags/interface.inc.php';
require_once 'inc/tags/tags.inc.php';
$profile_begin = microtime(true);
$prj = new Tags_Project('tcms.interface.tags');
$method = 'post';
project_init_params($prj, $method);
$query = 'io_' . $method;
$site = $query('site');
$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);
    }
<?php

/**
 * 提供文章的分词结果Top3,来搜索相近的Tags
 */
require_once 'header/web.inc.php';
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 接口调用出错");
    }