Example #1
0
function kc_grab_regexcallback($m)
{
    global $king;
    if (!kc_validate($m[5], 7)) {
        return $m[0];
    }
    if ($path = kc_grab_get($m[5])) {
        if ($m[5] == $path) {
            //如果录入的和返回的路径一样的话,存储失败
            return $m[0];
        } else {
            return $m[1] . $m[3] . $m[4] . $king->config('inst') . $path . $m[4] . $m[6];
        }
    } else {
        return $m[0];
    }
    preg_match_all('/([\\w\\-]+)=(["\'])(.*?)\\2/s', $m[0], $array, PREG_SET_ORDER);
    $newArray = array();
    if (is_array($array)) {
        foreach ($array as $val) {
            $newArray += array(strtolower($val[1]) => strtolower($val[3]));
        }
    }
}
Example #2
0
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">&nbsp;</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);
}