function king_edt() { global $king; $king->access('portal_content_edt'); //初始化 $listid = kc_get('listid', 2, 1); //$info['listid']; $info = $king->portal->infoList($listid); $model = $king->portal->infoModel($info['modelid']); // kc_error('<pre>'.print_r($array_field,1)); $kid = kc_get('kid', 2); $kid1 = kc_get('kid1', 2); $isadmin = $kid1 ? 'isadmin2' : 'isadmin1'; //次页:首页 $array_field = array_keys($model['field'][$isadmin]); $sql_field = implode(',', $array_field); //[tablemodel]字段调用 // $listid=kc_get('listid',2); if ($GLOBALS['ismethod'] || $kid == '') { //POST过程或新添加的过程 $data = $_POST; if (!$GLOBALS['ismethod']) { //初始化新添加的数据 $data['kpath'] = $king->portal->depathMode($info); $data['nshow'] = 1; $array_field_default = $model['field']['default']; foreach ($array_field_default as $key => $val) { $data[$key] = $val; } } } else { //编辑数据,从数据库读出 if (!($data = $king->db->getRows_one('select ' . $sql_field . ' from %s__' . $model['modeltable'] . ' where kid=' . $kid . ' limit 1;'))) { kc_error($king->lang->get('system/error/param') . '<br/>select ' . $sql_field . ' from %s__' . $model['modeltable'] . ' where kid=' . $kid . ' limit 1;' . '<br/>File:' . basename(__FILE__) . ';Line:' . __LINE__); } } $data = kc_data($array_field, $data); $data['kid'] = $kid; if (!($res = $king->db->getRows("select * from %s_field where modelid={$info['modelid']} and {$isadmin}=1 and kid1=0 order by norder,kid;"))) { //全部调用 $res = array(); } $s = $king->openForm('manage.content.php?action=edt'); $s .= kc_htm_hidden(array('listid' => $listid, 'kid' => $kid, 'kid1' => $kid1)); //这个隐藏域不要放在下面 //kc_error("select * from %s_field where modelid={$info['modelid']} and {$isshow}=1 and kid1=0 order by norder,kid;"); //kc_error('<pre>'.print_r($res,1)); foreach ($res as $rs) { $s .= $king->portal->formdecode($rs, $data, $info, 1, $kid1 ? 2 : 1); } $s .= $king->htmForm($king->lang->get('portal/common/exp'), kc_htm_checkbox('pag', array(1 => $king->lang->get('portal/goto/addpag')), kc_post('pag'))); $s .= $king->closeForm('save'); //数据处理 if ($GLOBALS['ischeck']) { $_array = array(); //设置为空数组 //收集字段的值 foreach ($array_field as $val) { if (in_array($val, array('nshow', 'nhead', 'ncommend', 'nup', 'nfocus', 'nhot')) || array_key_exists($val, $model['field']['offon'])) { //增加判断offon $_array[$val] = $data[$val] ? 1 : 0; } else { if (is_array($data[$val])) { $_array[$val] = implode(',', $data[$val]); } else { $_array[$val] = $data[$val]; } //抓图和过滤链接 if ($val == 'kcontent') { if (kc_post('isgrab')) { //抓图 $_array[$val] = kc_grab($_array[$val]); } if (kc_post('isremovea')) { //过滤链接 $_array[$val] = preg_replace('/<a ([^>]*)>|<\\/a>/is', '', $_array[$val]); } if (kc_post('isremovetable')) { //过滤表格 $_array[$val] = preg_replace('/<(table|tbody|thead|tr|td|th|caption) ?([^>]*)>|<\\/(table|tbody|thead|tr|td|th|caption)>/is', '', $_array[$val]); } if (kc_post('isremovestyle')) { //过滤样式 $_array[$val] = preg_replace('/(<([^>]*))( style=)(["\'])(.*?)\\4(([^>]*)\\/?>)/is', '$1 $6', $_array[$val]); } if (kc_post('isremoveid')) { //过滤样式 $_array[$val] = preg_replace('/(<([^>]*))( id=)(["\'])(.*?)\\4(([^>]*)\\/?>)/is', '$1 $6', $_array[$val]); } if (kc_post('isremoveclass')) { //过滤样式 $_array[$val] = preg_replace('/(<([^>]*))( class=)(["\'])(.*?)\\4(([^>]*)\\/?>)/is', '$1 $6', $_array[$val]); } } } } if (in_array('kimage', $_array) && in_array('kcontent', $_array)) { //如果有选择第一个图作为缩略图 并 kimage在列表里 if (kc_post('isoneimage')) { //抓第一张图为缩略图 if ($oneimage = preg_match('/(<img([^>]*))( src=)(["\'])(.*?)\\4(([^>]*)\\/?>)/is', $_array['kcontent'], $oneimage_array)) { $smartimg = $oneimage_array[5]; if (is_file(ROOT . substr($smartimg, strlen($king->config('inst'))))) { //判断是否为本地文件 $_array['kimage'] = substr($smartimg, strlen($king->config('inst'))); } else { //若是远程文件,则抓取 if ($path = kc_grab_get($smartimg)) { //抓取成功 if ($path != $smartimg) { //值不一样,说明抓取成功 $_array['kimage'] = $path; } } } } } } //listid & kid1 $_array['listid'] = $data['listid']; $_array['kid1'] = $data['kid1'] ? $data['kid1'] : 0; /** 检查kpath是否在键名列表里,如果有则判断是否为空值 如果没有,则补充 */ if (empty($_array['kpath'])) { $_array['kpath'] = $king->portal->depathMode($info); } /** 检查kkeywords,如果没有,则自动补充其值 如果有,则更新列表 */ $_array['kkeywords'] = !empty($data['kkeywords']) ? $king->portal->getKey($_array['ktitle'], $_array['kkeywords']) : $king->portal->getKey($_array['ktitle']); /** 关键字替换功能的实现概论 从$_array['kkeywords']中获得关键字列表,从预置的[关键字链接页/待做的表]中查找相关关键字 kname 关键字 kkeywords 关键字相关关键字 kpath 关键字链接网址 preg_replace('',$rs['kpath'],$_array['kcontent'],1); */ /** 检查ktag,如果没有,则自动补充其值 如果有,则更新列表 */ $_array['ktag'] = !empty($data['ktag']) ? $king->portal->getTag($_array['ktitle'], $_array['ktag']) : $king->portal->gettag($_array['ktitle']); /** 如果description值为空,则从content中获取 */ if (empty($data['kdescription']) && !empty($data['kcontent'])) { $kdescription = strip_tags($data['kcontent']); $kdescription = preg_replace('/(\\&[a-z]{1,6};)|\\s/', '', $kdescription); $_array['kdescription'] = kc_substr($kdescription, 0, 200); } //副标题长度 $_array['nsublength'] = isset($data['ksubtitle']) ? kc_strlen($data['ksubtitle']) : 0; //更新时间 $_array['nlastdate'] = time(); //如果有kid1值,则对kid1对应的nlastdate进行更新 if ($kid1) { $king->db->update('%s__' . $model['modeltable'], array('nlastdate' => time()), 'kid=' . $kid1); } //图片框写远程路径的时候,抓图 foreach ($model['field']['image'] as $key => $val) { if (isset($_array[$key])) { //当有image类型的字段的时候,检查一下其值 if (kc_validate($_array[$key], 6)) { //若为网址类型的话,自动抓图到本地 $_array[$key] = kc_grab_get($_array[$key]); } } } //添加&更新数据 if ($kid) { //update $king->db->update('%s__' . $model['modeltable'], $_array, 'kid=' . $kid); $_nlog = 7; } else { $_array['ndate'] = time(); $_array['adminid'] = $king->admin['adminid']; $_array['userid'] = -1; $_array['norder'] = $king->db->neworder('%s__' . $model['modeltable']); //不同的浏览器不同的分页标签,前台不支持 switch (strtolower($king->admin['admineditor'])) { case 'fckeditor': $pagebreak = '<div style="page-break-after: always"><span style="display: none"> </span></div>'; break; case 'tiny_mce': $pagebreak = '<!-- pagebreak -->'; break; case 'edit_area': $pagebreak = '<!-- pagebreak -->'; break; } if (isset($pagebreak) && isset($_array['kcontent'])) { $array = explode($pagebreak, $_array['kcontent']); foreach ($array as $key => $val) { $_array['kcontent'] = $val; $_array['norder']++; if ($key === 0) { //第一个 $kid = $king->db->insert('%s__' . $model['modeltable'], $_array); } else { $_array['kpath'] = $king->portal->depathMode($info); $_array['kid1'] = $data['kid1'] ? $data['kid1'] : $kid; $king->db->insert('%s__' . $model['modeltable'], $_array); } } } else { $kid = $king->db->insert('%s__' . $model['modeltable'], $_array); } $_nlog = 5; if ($kid == 0) { kc_error($king->lang->get('system/error/insert') . kc_clew(__FILE__, __LINE__, nl2br(print_r($_array, 1)))); } } //更新列表信息 $king->portal->lastUpdated($listid, 'list'); //删除缓存重建缓存 $king->cache->del('portal/list/' . $listid); kc_f_delete($king->config('xmlpath', 'portal') . '/portal/' . $info['modelid'] . '/' . wordwrap($kid, 1, '/', 1) . '.xml'); $id = $king->portal->infoID($listid, $kid); if ($kid1) { kc_f_delete($king->config('xmlpath', 'portal') . '/portal/' . $info['modelid'] . '/' . wordwrap($kid1, 1, '/', 1) . '.xml'); $id = $king->portal->infoID($listid, $kid1); } //生成操作 if ($info['npage'] == 0) { if ($info['npagenumber'] == 1) { $king->portal->createPage($listid, $kid1 ? $kid1 : $kid); //$listid,$kid,$pid=1,$is=null $subkid = $id['subkid']; if ($subkid) { $subid = explode(',', $subkid); foreach ($subid as $sid) { $king->portal->createPage($listid, $sid); } } } else { $pcount = ceil($id['ncount'] / $info['npagenumber']); for ($i = 1; $i <= $pcount; $i++) { $king->portal->createPage($listid, $kid1 ? $kid1 : $kid, $i); } } } //写log $king->log($_nlog, $model['modeltable'] . ':' . $data['ktitle']); // if(kc_post('pag')[0]==1){ if (kc_post('pag') == 1) { $s = kc_goto($king->lang->get('system/goto/saveok'), 'manage.content.php?action=edtpag&listid=' . $data['listid'] . '&kid1=' . ($kid1 ? $kid1 : $kid)); } else { if ($kid1) { kc_goto($king->lang->get('system/goto/is'), 'manage.content.php?action=edtpag&listid=' . $data['listid'] . '&kid1=' . $kid1, 'manage.content.php?action=pag&listid=' . $data['listid'] . '&kid1=' . $kid1); } else { kc_goto($king->lang->get('system/goto/is'), 'manage.content.php?action=edt&listid=' . $data['listid'], 'manage.content.php?listid=' . $data['listid']); } } } list($left, $right) = king_inc_list(); $king->skin->output($info['ktitle'], $left, $right, $s); }
/** 格式化字符串 @param string $s : 字符模板 @paran string $attrib : 字符串属性,应该是size="20"这种类型的,具体做的时候还得进行输出判断,attrib可能的取值如下 width,height : 如果有这两个或一个属性,则对$str进行文件判断,如果是则进行相关图片处理操作 replace : 字符串替换,replace="A|B",A替换为B size : 字符长度设置 code : 字符转换js/html none : 空值替换属性 */ private function str_format($s, $attrib) { if (empty($attrib)) { return $s; } //如果是空值,则直接返回s值 //转换 if (array_key_exists('formatstr', $attrib)) { $code = $attrib['formatstr']; if (isset($code[0])) { switch (strtolower($code)) { case 'javascript': $s = str_replace(array('\'', "\n", chr(13)), array('\\\'', '\\n', ''), $s); break; case 'urlencode': $s = urlencode($s); break; case 'addslashes': $s = addslashes($s); break; case 'md5': $s = md5($s); break; } } } //应用函数 if (array_key_exists('fun', $attrib)) { $fun = $attrib['fun']; $funs = explode(',', $fun); $array = array(1 => $s); foreach ($funs as $fun) { if (function_exists($fun)) { //如果有指定的函数,则应用 $array1 = array_map($fun, $array); } } $s = $array1[1]; } //替换 if (array_key_exists('replace', $attrib)) { $replace = $attrib['replace']; if (is_array($replace)) { foreach ($replace as $key => $val) { $s = str_replace($key, $val, $s); } } /* if(isset($replace{0})){ list($find,$new)=kc_explode('|',$replace,2); $s=str_replace($find,$new,$s); } */ } //长度 if (array_key_exists('size', $attrib)) { $size = $attrib['size']; if ($size) { if (kc_validate($size, 2)) { $s = kc_substr($s, 0, $size); } } } //日期格式化 if (array_key_exists('formatdate', $attrib)) { $format = $attrib['formatdate']; if (kc_validate($s, 2)) { //默认的时间是int类型的 $s = kc_formatdate($s, $format); } elseif (kc_validate($s, 9)) { //日期类型 2008-11-9这种格式 list($yy, $mm, $dd) = explode('-', $s); $s = kc_formatdate(gmmktime(0, 0, 0, $mm, $dd, $yy), $format); //需要转换一下字符 } } //数字格式化 if (array_key_exists('formatnumber', $attrib)) { if (kc_validate($attrib['formatnumber'], 2)) { $s = number_format($s, $attrib['formatnumber']); } } //缩略图 if (array_key_exists('width', $attrib) || array_key_exists('height', $attrib)) { if (array_key_exists('width', $attrib)) { $width = $attrib['width']; } if (array_key_exists('height', $attrib)) { $height = $attrib['height']; } if (($width || $height) && isset($s[0])) { $s = kc_image($s, $attrib); } } //默认填充 if (array_key_exists('none', $attrib)) { $none = $attrib['none']; if (!isset($s[0])) { $s = $none; } } //前面插入 if (array_key_exists('before', $attrib)) { $before = $attrib['before']; if (isset($before[0]) && isset($s[0])) { $s = $before . $s; } } //后面插入,条件是$s不能为空 if (array_key_exists('after', $attrib)) { $after = $attrib['after']; if (isset($after[0]) && isset($s[0])) { $s .= $after; } } return $s; }
function king_ajax_payment() { global $king; // setcookie('KingCMS_Cart',serialize($cart),time()+86400000,$king->config('inst')); $oid = kc_get('oid', 2, 1); $array_black = str_split('<>\'"%'); if (!($data = $king->db->getRows_one("select ono,kname,nnumber,ntotal,kfeedback,eid,nexpress from %s_orders where oid={$oid}"))) { kc_error($king->lang->get('system/error/param')); } $s = '<table class="k_table_list" cellspacing="0">'; $s .= '<caption>' . $king->lang->get('portal/cart/prodinfo') . '</caption>'; $s .= '<tr><th class="w150">' . $king->lang->get('portal/cart/youorders') . '</th><td><strong class="red">' . $data['ono'] . '</strong></td></tr>'; $s .= '<tr><th>' . $king->lang->get('portal/cart/prodname') . '</th><td>' . $data['kname'] . '</td></tr>'; $s .= '<tr><th>' . $king->lang->get('portal/cart/total') . '</th><td>' . $data['nnumber'] . '件</td></tr>'; $s .= '<tr><th>' . $king->lang->get('portal/cart/alltotal') . '</th><td>' . number_format($data['ntotal'], 2) . '</td></tr>'; $s .= '</table>'; $s .= '<br/>'; $height = 0; $s .= '<table class="k_table_list" cellspacing="0">'; $s .= '<caption>' . $king->lang->get('portal/cart/payment') . '</caption>'; $server_name = $_SERVER['SERVER_NAME']; //财付通付款 if ($king->config('tenpaykey', 'portal') && $king->config('tenpayseller', 'portal')) { $height++; $s .= '<tr><th>' . $king->lang->get('portal/cart/tenpay') . '</th><td>'; $payurl = "https://www.tenpay.com/cgi-bin/med/show_opentrans.cgi?"; $href = "attach=" . $oid; //利用attach传递oid值 $href .= "&chnid=" . $king->config('tenpayseller', 'portal'); $href .= "&cmdno=12"; $href .= "&encode_type=2"; $desc = kc_substr(str_replace($array_black, '', $data['kfeedback']), 0, 32); //留言信息 $href .= isset($desc[0]) ? "&mch_desc=" . $desc : ''; //需要过滤<>’”% $href .= "&mch_name={$data['kname']}"; //需要过滤<>’”% $href .= "&mch_price=" . $data['ntotal'] * 100; $href .= "&mch_returl=http://" . $server_name . $king->config('inst') . 'api/tenpay.php'; //通知URL $href .= "&mch_type=1"; //交易类型1实物交易2虚拟交易 $href .= "&mch_vno=" . substr($data['ono'], -12); //交易号 $href .= "&need_buyerinfo=2"; $href .= "&seller=" . $king->config('tenpayseller', 'portal'); //收款财付通帐号 $href .= "&show_url=http://" . $server_name . $king->config('inst') . 'portal/tenpay.php'; //快递信息 $express = $king->portal->getExpress(); if (isset($express[$data['eid']])) { //有快递信息的时候 $ename = $express[$data['eid']]['kname']; $href .= isset($ename[0]) ? "&transport_desc=" . $ename : ''; } $href .= "&transport_fee=" . $data['nexpress'] * 100; //物流费用 $href .= "&version=2"; $md5_sign = strtoupper(md5($href . '&key=' . $king->config('tenpaykey', 'portal'))); $href .= "&sign=" . $md5_sign; $href = $payurl . $href; $s .= '<p><a href="' . $href . '" target="_blank"><img src="' . $king->config('inst') . 'portal/images/tenpay.gif"/></a></p>'; $s .= '</td></tr>'; } //支付宝付款 if ($king->config('alipayregmail', 'portal') && $king->config('alipaypartner', 'portal') && $king->config('alipaykey', 'portal')) { $height++; $payurl = "http://www.alipay.com/cooperate/gateway.do?"; $body = kc_substr($data['kfeedback'], 0, 200); //留言信息 switch ($data['eid']) { case 1: $logistics_type = 'EMS'; break; //这是默认的方案,客户自行改动则没办法。 //这是默认的方案,客户自行改动则没办法。 case 2: $logistics_type = 'POST'; break; default: $logistics_type = 'EXPRESS'; } $hrf = array(); $hrf['_input_charset'] = 'utf-8'; //编码 $hrf['service'] = 'trade_create_by_buyer'; //接口名称 $hrf['seller_email'] = $king->config('alipayregmail', 'portal'); //支付宝注册邮箱 $hrf['partner'] = $king->config('alipaypartner', 'portal'); //商户ID $hrf['payment_type'] = 1; //支付类型 $hrf['out_trade_no'] = $data['ono']; //订单号 $hrf['subject'] = $data['kname']; //商品名称 if (isset($body[0])) { $hrf['body'] = $body; } //内容 $hrf['price'] = number_format($data['ntotal'], 2); //单价 $hrf['quantity'] = 1; //数量 $hrf['logistics_type'] = $logistics_type; //物流类型 $hrf['logistics_payment'] = 'BUYER_PAY'; //由谁负责物流费用 $hrf['logistics_fee'] = number_format($data['nexpress'], 2); //物流费用 $hrf['notify_url'] = 'http://' . $server_name . '/api/alipay.php'; //通知URL ksort($hrf); $href = $payurl; $hrf_sign = array(); foreach ($hrf as $key => $val) { $hrf_sign[] = $key . '=' . $val; $href .= $key . '=' . urlencode($val) . '&'; } $sign = md5(implode('&', $hrf_sign) . $king->config('alipaykey', 'portal')); //生成签名 $href .= "sign={$sign}&sign_type=MD5"; $s .= '<tr><th>' . $king->lang->get('portal/cart/alipay') . '</th><td>'; $s .= '<p><a href="' . $href . '" target="_blank"><img src="' . $king->config('inst') . 'portal/images/alipay.gif"/></a></p>'; } //银行汇款 $s .= '<tr><th class="w150">' . $king->lang->get('portal/const/transfer') . '</th><td>'; $s .= '<p>'; $s .= '<a href="' . $king->config('inst') . 'portal/cart.php?action=bank&oid=' . $oid . '" target="_blank"><img src="' . $king->config('inst') . 'portal/images/bank.gif"/></a><br/>'; $s .= '<a href="javascript:;" rel="{URL:\'' . $king->config('inst') . 'portal/cart.php\',CMD:\'transfer\',IS:1}" class="k_ajax">' . $king->lang->get('portal/orders/viewmethod') . '</a>'; $s .= '</p>'; $s .= '</td></tr>'; $s .= '</table>'; kc_ajax($king->lang->get('portal/cart/myorders'), $s, 0, '', 500, 310 + $height * 50); }
function king_ajax_faq() { global $king; $king->access(0); $modules = $king->getModule(); $module = kc_post('module'); $num = kc_post('num'); $s = '<div id="k_faq"><p class="k_faq_nav">'; $s .= '<a class="k_ajax" rel="{CMD:\'faq\',URL:\'../system/manage.php\',IS:1}">' . kc_icon('a1') . 'HOME</a>'; $s .= '</p>'; if (!$module) { //如果module为空 $s .= '<p>' . kc_icon('l9') . '<a href="javascript:;" class="k_ajax" rel="{CMD:\'faq\',module:\'system\',URL:\'../system/manage.php\',IS:1}">' . $king->lang->get('system/name') . '</a></p>'; foreach ($modules as $val) { if (file_exists(ROOT . $val . '/faq/' . $king->admin['adminlanguage'] . '.xml')) { $s .= '<p>' . kc_icon('l9') . '<a href="javascript:;" class="k_ajax" rel="{CMD:\'faq\',module:\'' . $val . '\',IS:1,URL:\'../system/manage.php\'}">' . $king->lang->get($val . '/name') . '</a></p>'; } } $s .= '<p> </p>'; $s .= '<p>' . kc_icon('e9') . '<a href="http://help.kingcms.com/" target="_blank">' . $king->lang->get('system/login/manual') . '</a></p>'; $s .= '<p>' . kc_icon('n1') . '<a href="javascript:;" class="k_ajax" rel="{CMD:\'novice\',IS:1,URL:\'../system/manage.php\'}">' . $king->lang->get('system/level/novice') . '</a></p>'; } else { $doc = new DOMDocument(); $filepath = ROOT . $module . '/faq/' . $king->admin['adminlanguage'] . '.xml'; $doc->load($filepath); $path = new DOMXPath($doc); $title = @$path->evaluate('//kingcms/item/title'); if (kc_validate($num, 2)) { $s .= '<h3>' . $title->item($num)->nodeValue . '</h3><hr/>'; $body = @$path->evaluate('//kingcms/item/body'); $s .= '<p>' . nl2br($body->item($num)->nodeValue) . '</p>'; $s .= '<p class="k_faq_nav">' . kc_icon('c9') . '<a href="javascript:;" class="k_ajax" rel="{CMD:\'faq\',module:\'' . $module . '\',URL:\'../system/manage.php\',IS:1}">' . $king->lang->get('system/common/backlist') . '</a></p>'; } else { // kc_error($title->length); $count = $title->length; // kc_error('<pre>'.print_r($title,1)); for ($i = 0; $i < $count; $i++) { $s .= '<p>' . kc_icon('n8') . '<a href="javascript:;" class="k_ajax" rel="{CMD:\'faq\',module:\'' . $module . '\',num:' . $i . ',URL:\'../system/manage.php\',IS:1}">' . kc_substr($title->item($i)->nodeValue, 0, 60) . '</a></p>'; } $s .= '<p class="k_faq_nav">' . kc_icon('c9') . '<a href="javascript:;" class="k_ajax" rel="{CMD:\'faq\',IS:1,URL:\'../system/manage.php\'}">' . $king->lang->get('system/login/home') . '</a></p>'; } } if (kc_validate($num, 2)) { } $s .= '</div>'; kc_ajax($king->lang->get('system/common/faq'), $s, 0, '', 500, 350); }
function king_edt() { global $king; $king->load('user'); //初始化zf $listid = kc_get('listid', 2, 1); //$info['listid']; $info = $king->portal->infoList($listid); $model = $king->portal->infoModel($info['modelid']); $kid = kc_get('kid', 2); $kid1 = kc_get('kid1', 2); $isuser = $kid1 ? 'isuser2' : 'isuser1'; //次页:首页 $array_field = array_keys($model['field'][$isuser]); $sql_field = implode(',', $array_field); //[tablemodel]字段调用 //读取管理员列表 $editors = $king->portal->getListEditor($listid); if (!is_array($editors)) { $editors = array(); } //用户权限及登录验证 if ($info['gidpublish'] == -1) { $user = array('userid' => 0, 'username' => '[' . $king->lang->get('user/name/guest') . ']'); } else { $user = $king->user->access(); if (!in_array($king->user->userid, $editors) && $info['gidpublish']) { //非栏目编辑 并 限制组会员 ;栏目编辑员则跳过此验证 $king->user->access($info['gidpublish']); } } //发帖验证,检查是否为不允许发布 //0不允许发布|1直接发布|2验证后发布 if (!in_array($user['userid'], $editors)) { //栏目编辑员无需验证 if ((int) $info['ispublish' . ($kid1 ? 2 : 1)] === 0) { $king->portal->error($king->lang->get('portal/title/stop'), $king->lang->get('portal/error/stop')); } } //当kid有值的时候(编辑),进行所有权验证 if ($kid) { $user = empty($user) ? $king->user->access() : $user; //如果$user为null则进行登录验证,目的是要获得userid $id = $king->portal->infoID($listid, $kid); if (in_array($king->user->userid, $editors) || (int) $id['userid'] === (int) $king->user->userid) { if (!in_array($king->user->userid, $editors)) { //如果不是栏目管理员,则进行有效期验证 if (time() - $model['nlocktime'] * 3600 > $id['ndate'] && (int) $model['nlocktime'] !== 0) { //如果超过可允许编辑时间期限 并 可编辑时间不能为0,则提示错误 $king->portal->error($king->lang->get('portal/title/stop'), $king->lang->get('portal/error/timeout')); } } } else { $king->portal->error($king->lang->get('portal/title/stop'), $king->lang->get('portal/error/noaccess')); } } $fields = explode(',', $sql_field); if ($GLOBALS['ismethod'] || $kid == '') { //POST过程或新添加的过程 $data = $_POST; if (!$GLOBALS['ismethod']) { //初始化新添加的数据 $data['kpath'] = $king->portal->depathMode($info); $data['nshow'] = 1; $array_field_default = $model['field']['default']; foreach ($array_field_default as $key => $val) { $data[$key] = $val; } //从URL中获取初始值 foreach ($fields as $val) { if (isset($_GET[$val])) { $data[$val] = $_GET[$val]; } } } } else { //编辑数据,从数据库读出 //判断是否为栏目编辑 或 所有人 if (!($data = $king->db->getRows_one('select ' . $sql_field . ' from %s__' . $model['modeltable'] . ' where kid=' . $kid . ' limit 1;'))) { kc_error($king->lang->get('system/error/param') . '<br/>select ' . $sql_field . ' from %s__' . $model['modeltable'] . ' where kid=' . $kid . ' limit 1;' . '<br/>File:' . basename(__FILE__) . ';Line:' . __LINE__); } } $data = kc_data($fields, $data); $data['kid'] = $kid; if (!($res = $king->db->getRows("select * from %s_field where modelid={$info['modelid']} and {$isuser}=1 and kid1=0 order by norder,kid;"))) { //全部调用 $res = array(); } $s = $king->openForm('index.php?action=edt'); $s .= kc_htm_hidden(array('listid' => $listid, 'kid' => $kid, 'kid1' => $kid1)); //这个隐藏域不要放在下面 foreach ($res as $rs) { $s .= $king->portal->formdecode($rs, $data, $info, 0, $kid1 ? 2 : 1); } $s .= $king->closeForm($king->lang->get('system/common/publish')); //数据处理 if ($GLOBALS['ischeck']) { $_array = array(); //设置为空数组 //收集字段的值 foreach ($array_field as $val) { if (substr($val, 0, 1) == 'n') { $_array[$val] = $data[$val] ? 1 : 0; } else { if (is_array($data[$val])) { $_array[$val] = implode(',', $data[$val]); } else { $_array[$val] = $data[$val]; } } } //listid & kid1 $_array['listid'] = $data['listid']; $_array['kid1'] = $data['kid1'] ? $data['kid1'] : 0; /** 检查kpath是否在键名列表里,如果有则判断是否为空值 如果没有,则补充 */ if (empty($_array['kpath'])) { $_array['kpath'] = $king->portal->depathMode($info); } /** 检查kkeywords,如果没有,则自动补充其值 如果有,则更新列表 */ $_array['kkeywords'] = !empty($data['kkeywords']) ? $king->portal->getKey($_array['ktitle'], $_array['kkeywords']) : $king->portal->getKey($_array['ktitle']); /** 检查ktag,如果没有,则自动补充其值 如果有,则更新列表 */ $_array['ktag'] = !empty($data['ktag']) ? $king->portal->getTag($_array['ktitle'], $_array['ktag']) : $king->portal->gettag($_array['ktitle']); /** 如果description值为空,则从content中获取 */ if (empty($data['kdescription']) && !empty($data['kcontent'])) { $kdescription = strip_tags($data['kcontent']); $kdescription = preg_replace('/\\&[a-z]{1,6};/', '', $kdescription); $_array['kdescription'] = kc_substr($kdescription, 0, 200); } //副标题长度 $_array['nsublength'] = isset($data['ksubtitle']) ? kc_strlen($data['ksubtitle']) : 0; //更新时间 $_array['nlastdate'] = time(); //如果有kid1值,则对kid1对应的nlastdate进行更新 if ($kid1) { $king->db->update('%s__' . $model['modeltable'], array('nlastdate' => time()), 'kid=' . $kid1 . ' limit 1'); } //添加&更新数据 if ($kid) { //update $king->db->update('%s__' . $model['modeltable'], $_array, 'kid=' . $kid); $_nlog = 7; } else { $_array['ndate'] = time(); $_array['norder'] = $king->db->neworder('%s__' . $model['modeltable']); $_array['userid'] = $user['userid']; $_array['nshow'] = $info['ispublish' . ($kid1 ? 2 : 1)]; $kid = $king->db->insert('%s__' . $model['modeltable'], $_array); $_nlog = 5; if ($kid == 0) { kc_error($king->lang->get('system/error/insert') . kc_clew(__FILE__, __LINE__, nl2br(print_r($_array, 1)))); } } //更新列表信息 $king->portal->lastUpdated($listid, 'list'); //删除缓存重建缓存 $king->cache->del('portal/list/' . $listid); kc_f_delete($king->config('xmlpath', 'portal') . '/portal/' . $info['modelid'] . '/' . wordwrap($kid, 1, '/', 1) . '.xml'); $id = $king->portal->infoID($listid, $kid); if ($kid1) { kc_f_delete($king->config('xmlpath', 'portal') . '/portal/' . $info['modelid'] . '/' . wordwrap($kid1, 1, '/', 1) . '.xml'); $id = $king->portal->infoID($listid, $kid1); } //生成操作 if ($info['npage'] == 0) { if ($info['npagenumber'] == 1) { $king->portal->createPage($listid, $kid1 ? $kid1 : $kid); //$listid,$kid,$pid=1,$is=null $subkid = $id['subkid']; if (isset($subkid)) { $subid = explode(',', $subkid); foreach ($subid as $sid) { $king->portal->createPage($listid, $sid); } } } else { $pcount = ceil($id['ncount'] / $info['npagenumber']); for ($i = 1; $i <= $pcount; $i++) { $king->portal->createPage($listid, $kid1 ? $kid1 : $kid, $i); } } } //跳转,当留言反馈类型的时候,这个跳转需要改动 echo "<script type=\"text/javascript\">parent.location='" . $king->portal->pathPage($info, $id['kid'], $id['kpath']) . "'</script>"; } $tmp = new KC_Template_class($model['ktemplatepublish']); $tmp->assign('inside', $s); $tmp->assign('listid', $listid); $tmp->assign('title', $info['klistname']); $tmp->assign('type', 'edit'); echo $tmp->output(); // list($left,$right)=king_inc_list(); // $king->skin->output($king->lang->get('portal/title/content'.($kid?'edt':'add')),$left,$right,$s); }