$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); }
$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(), '', ''); } function _log($msg, $level = 'ERROR') { global $prj; $prj->CLog->w($level, $msg); }