/** * 请求数据检测 * @param $sType 操作类型 add:添加,edit:修改: * @param $iOptype 操作类型 0:保存,1:发布 * @return mixed * */ public function _checkData($sType = 'add', $param = array()) { $aRow = empty($param) ? $this->_getParams() : $param; //保存和发布都需要做的判断 if (!Util_Validate::isCLength($aRow['sTitle'], 5, 22)) { return $this->showMsg('资讯标题长度范围为5到22个字!', false); } if (!empty($param) || $aRow['iOptype'] > 0) { if (!Util_Validate::isCLength($aRow['sShortTitle'], 5, 15)) { return $this->showMsg('短标题长度范围为5到15个字!', false); } if (!Util_Validate::isCLength($aRow['sAuthor'], 2, 20)) { return $this->showMsg('资讯作者长度范围为2到20个字!', false); } if (!Util_Validate::isCLength($aRow['sMedia'], 1, 20)) { return $this->showMsg('媒体来源长度范围为1到20个字!', false); } if (!Util_Validate::isCLength($aRow['sKeyword'], 2, 50)) { return $this->showMsg('关键字长度范围为2到20个字!', false); } if (empty($aRow['sImage'])) { return $this->showMsg('请选择一张默认图片!', false); } if (!Util_Validate::isCLength($aRow['sAbstract'], 60, 90)) { return $this->showMsg('资讯摘要长度范围为60到90个字!', false); } if (!Util_Validate::isCLength($aRow['sContent'], 100, 16777215)) { return $this->showMsg('资讯内容长度范围为100到65535个字!', false); } if ($aRow['iCategoryID'] < 0) { return $this->showMsg('请选择一个资讯分类!', false); } if ($aRow['iPublishTime'] == 0) { $iPublishTime = time(); } if (!Model_Author::getAuthorByName($aRow['sAuthor'])) { return $this->showMsg('作者不存在', false); } /** if (Model_News::EVALUATION_NEWS == $this->_getTypeID()) { if (empty($aRow['sLoupanID'])) { return $this->showMsg('请添加推送楼盘', false); } }*/ if ($aRow['sLoupanID']) { $aLoupanID = explode(',', $aRow['sLoupanID']); foreach ($aLoupanID as $key => $value) { if (!Model_CricUnit::getLoupanByID($value)) { unset($aLoupanID[$key]); $iLouChange = 1; //楼盘ID过滤标记 //return $this->showMsg('推送楼盘不存在', false); } } if (isset($iLouChange)) { $aRow['sLoupanID'] = implode(',', $aLoupanID); } } if ($aRow['sTag']) { $sTag = explode(',', $aRow['sTag']); foreach ($sTag as $key => $value) { $aTag = Model_Tag::getDetail($value); if (empty($aTag) || $aTag['iStatus'] != 1 || $aTag['iTypeID'] != $this->_getTypeTag()) { return $this->showMsg('资讯标签不存在,无效标签名称为(' . $value . ')', false); } } } } //去掉非字段的元素 unset($aRow['iOptype']); return $aRow; }
/** * 修改文章中带楼盘名的内容 * @param $aNews */ public static function changeNewsLouName(&$aNews) { if ($aNews['sLoupanID']) { $sNewsIDs = explode(',', $aNews['sLoupanID']); //按楼盘名字长度进行排序 $aIDsTemp = array(); //ID排序后数组 foreach ($sNewsIDs as $key => $value) { $sLouName = Model_CricUnit::getLoupanNames($value); $aLoupan[$value] = isset($sLouName[$value]) ? $sLouName[$value] : ''; } uasort($aLoupan, array('self', '_cmp')); $sNewsIDs = array_keys($aLoupan); foreach ($sNewsIDs as $key => $value) { $sContent = $aNews['sContent']; $aTmp = Model_CricUnit::getLoupanNames($value); if (empty($aTmp)) { continue; } $aLoupan = Model_CricUnit::getLoupanByID($value); $sUrl = Model_CricUnit::getUnitUrl($aLoupan['CityCode'], $aLoupan['RegionName'], $aLoupan['DistrictName'], $value); $sSubting = '<a target="_blank" href="' . $sUrl . '">' . $aTmp[$value] . '</a>'; $sLpName = $aTmp[$value]; $sAddPattern = "/" . $sLpName . "(?!([^<]*?)(<\\/a>|>|\\/>))/"; if (mb_strpos($sContent, $sLpName) !== false) { //存在楼盘名 $aNews['sContent'] = preg_replace($sAddPattern, $sSubting, $sContent); } } } }
/** * 编辑资讯 * * @return boolean */ public function editAction() { if ($this->isPost()) { $aNews = $this->_checkData('edit'); if (empty($aNews)) { return null; } $sAction = '保存'; if ($this->getParam('iOptype') > 0) { $aNews['iPublishStatus'] = 1; //发布需要将该字段改为1 $sAction = '发布'; } $aNews['iNewsID'] = intval($this->getParam('iNewsID')); //修改需要加上当前修改人ID $aCurrUserInfo = $this->aCurrUser; $aNews['iUpdateUserID'] = $aCurrUserInfo['iUserID']; if (1 == Model_News::updData($aNews)) { return $this->showMsg(['sMsg' => '资讯信息' . $sAction . '成功!', 'iNewsID' => $aNews['iNewsID']], true); } else { return $this->showMsg('资讯信息' . $sAction . '失败!', false); } } else { $this->_response->setHeader('Access-Control-Allow-Origin', '*'); $iNewsID = intval($this->getParam('id')); $aNews = Model_News::getDetail($iNewsID); /** Model_News::changeNewsLouName($aNews); print_r($aNews); die */ if ($aNews['sTag']) { $aNews['aTag'] = explode(',', $aNews['sTag']); } if ($aNews['iAuthorID'] == 0) { //处理老数据的作者问题 $aAuthor = Model_Author::getAll(['where' => ['sAuthorName' => $aNews['sAuthor']]]); if ($aAuthor) { foreach ($aAuthor as $author) { $aNews['iAuthorID'] = $author['iAuthorID']; if ($author['iCityID'] == $aNews['iCityID']) { break; } } } } $this->assign('aNews', $aNews); $aCategory = Model_Category::getPairCategorys($this->_getTypeCategory()); $aTag = $this->_getTagList(); //Model_Tag::getPairTags($this->_getTypeTag()); $aLoupan = Model_CricUnit::getLoupanNames($aNews['sLoupanID']); $this->assign('iTypeID', $this->_getTypeID()); $this->assign('iCityID', $this->_getCityID()); $this->assign('aCategory', $aCategory); $this->assign('aTag', $aTag); $this->assign('aLoupan', $aLoupan); $this->assign('sUploadUrl', Yaf_G::getConf('upload', 'url')); $this->assign('sFileBaseUrl', 'http://' . Yaf_G::getConf('file', 'domain')); } }