function form($A, $rs = array()) { $id = $A['field']; $rules = $A['rules']; $rs && ($v = $rs[$id]); if ($A['hidden'] == "1") { $FORM['hidden'] = '<input type="hidden" name="mVal[' . $id . ']" id="' . $id . '" value="' . $v . '" />'; } else { //判读是否为特殊字段 if (in_array($A['field'], array('cid', 'type', 'vlink'))) { switch ($A['field']) { case "cid": $catalog = new catalog(); $cata_option = $catalog->select($v, 0, 1, 'channel=1&list', $rs['mid']); if ($cata_option) { $html = '<select name="mVal[cid]" id="cid" style="width:auto;">'; $html .= '<option value="0"> == 请选择所属栏目 == </option>'; $html .= $cata_option; } else { $html = '<select name="mVal[cid]" id="cid" onclick="redirect(\'' . __SELF__ . '?do=catalog&operation=add\');">'; $html .= '<option value="0"> == 暂无栏目请先添加 == </option>'; } $html .= '</select>'; break; case "type": $html = '<select name="mVal[type][]" size="10" multiple="multiple" id="type">'; $html .= '<option value="0">默认属性[type=\'0\']</option>'; $html .= contenType("article"); $html .= '</select>'; $html .= selected($v, 'type', 'js'); break; case "vlink": $catalog = new catalog(); $html = '<select name="mVal[vlink][]" size="10" multiple="multiple" id="vlink">'; $html .= $catalog->select(0, 0, 1, 'channel=1&list&page', 'all'); $html .= '</select>'; $html .= selected($v, 'vlink', 'js'); break; // case in_array($A['field'],array('hits','digg','comments','visible','postype')): break; } } else { switch ($A['type']) { case in_array($A['type'], array('number', 'text', 'email', 'url')): $html = '<input type="text" name="mVal[' . $id . ']" class="txt" id="' . $id . '" value="' . $v . '" />'; break; case "radio": if ($rules) { foreach ($rules as $value => $text) { $checked = $value == $v ? ' checked="checked"' : ''; $html .= ' <input type="radio" name="mVal[' . $id . ']" class="radio" id="' . $id . '" value="' . $value . '" />' . $text; } } break; case "checkbox": if ($rules) { foreach ($rules as $value => $text) { $vArray = explode(',', $v); $checked = in_array($value, $vArray) ? ' checked="checked"' : ''; $html .= ' <input type="checkbox" name="mVal[' . $id . '][]" class="checkbox" id="' . $id . '.' . $value . '" value="' . $value . '" ' . $checked . '/>' . $text; } } break; case "textarea": $html = '<textarea name="mVal[' . $id . ']" id="' . $id . '" onKeyUp="textareasize(this)" class="tarea">' . $v . '</textarea>'; break; case "editor": $html = '<script type="text/javascript" src="' . $iCMS->dir . 'javascript/editor.js"></script>'; $html .= '<textarea name="mVal[' . $id . ']" id="' . $id . '" rows="30" cols="80" class="editor">' . $v . '</textarea>'; break; case "select": $html = '<select name="mVal[' . $id . ']" id="' . $id . '" style="width:auto;">'; $html .= '<option value="0"> == 不选择 == </option>'; if ($rules) { foreach ($rules as $value => $text) { $selected = $value == $v ? ' selected="selected"' : ''; $html .= '<option value="' . $value . '"' . $selected . '>' . $text . '</option>'; } } $html .= '</select>'; break; case "multiple": $html = '<select name="mVal[' . $id . '][]" id="' . $id . '" style="width:auto;" size="10" multiple="multiple">'; $html .= '<option value="0"> == 不选择 == </option>'; if ($rules) { foreach ($rules as $value => $text) { $vArray = explode(',', $v); $selected = in_array($value, $vArray) ? ' selected="selected"' : ''; $html .= '<option value="' . $value . '"' . $selected . '>' . $text . '</option>'; } } $html .= '</select>'; break; case "calendar": $value = empty($v) ? get_date($v, 'Y-m-d H:i:s') : $v; $html = '<input name="mVal[' . $id . ']" class="txt" value="' . $value . '" id="' . $id . '" type="text" onclick="showcalendar(event, this)"/>'; break; case "image": $html = '<input name="mVal[' . $id . ']" id="' . $id . '" type="text" value="' . $v . '" class="txt" style="width:450px"/>'; $html .= '<button type="button" class="selectdefault" to="pic"><span>选 择</span></button>'; $html .= '<div id="picmenu" style="display:none;">'; $html .= '<ul>'; $html .= '<li onClick="showDialog(\'' . __SELF__ . '.?do=dialog&operation=Aupload\',\'' . $id . '\',600,140);$(\'.close\').click();">本地上传</li>'; $html .= '<li onClick="showDialog(\'' . __SELF__ . '?do=dialog&operation=file&hit=file&type=gif,jpg,png,bmp\',\'' . $id . '\',600,500);$(\'.close\').click();">从网站选择</li>'; $html .= '<li onClick="showPic(\'' . $id . '\');$(\'.close\').click();">查看缩略图</li><li onClick="cutPic(\'' . $id . '\');$(\'.close\').click();">剪裁</li>'; $html .= '</ul></div>'; break; case "upload": $html = '<input name="' . $id . '" type="file" class="uploadbtn" id="' . $id . '" />'; break; } } $FORM['general'] = array('id' => $id, 'label' => $A['name'], 'description' => $A['description'], 'html' => $html); } if (!in_array($A['field'], getSystemField())) { $val = '$("#' . $id . '").val()'; //验证 switch ($A['validate']) { case "0": //不能为空 if ($A['type'] == "editor") { $js = 'var ' . $id . '_Editor = FCKeditorAPI.GetInstance(\'mVal[' . $id . ']\') ; if(' . $id . '_Editor.GetXHTML( true )==""){ alert("' . $A['name'] . '不能为空!"); ' . $id . '_Editor.focus(); return false; }'; } else { $js = 'if(' . $val . '==""){ alert("' . $A['name'] . '不能为空!"); $("#' . $id . '").focus(); return false;}'; } break; case "2": $js = 'var ' . $id . '_val = ' . $val . '; var pattern = /^\\d+(\\.\\d+)?$/; chkFlag = pattern.test(' . $id . '_val); if(!chkFlag){ alert("' . $A['name'] . '不是数字"); $("#' . $id . '").focus(); return false;}'; break; case "4": $js = 'var ' . $id . '_val = ' . $val . '; var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\\.[a-zA-Z0-9_-])+/; if(!pattern.test(' . $id . '_val)){ alert("邮箱地址的格式不正确!!"); $("#' . $id . '").focus(); return false;}'; break; case "5": $js = 'var ' . $id . '_val = ' . $val . '; var pattern = /^[a-zA-z]+:\\/\\/[^\\s]*/; if(!pattern.test(' . $id . '_val)){ alert("[' . $A['name'] . ']网址格式不正确!!"); $("#' . $id . '").focus(); return false;}'; break; } } $FORM['js'] = $js; // var_dump($FORM); // var_dump($A); return $FORM; }
function content($mId, $argv, $tpl = true) { $catalog = $this->cache('catalog.cache', 'include/syscache', 0, true); $sql = $this->linkmodeSQL('id', 'customlink', $argv); $__MODEL__ = $this->cache('model.id', 'include/syscache', 0, true); $model = $__MODEL__[$mId]; $__TABLE__ = $model['table'] . '_content'; $rs = $this->db->getRow("SELECT * FROM `#iCMS@__{$__TABLE__}` WHERE {$sql} AND `visible` ='1'"); empty($rs) && $this->error('error:page'); if ($catalog[$rs->cid]['ishidden']) { return false; } $rs->catalogdir = $this->cdir($catalog[$rs->cid]); $_urlArray = array('mId' => $mId, 'id' => $rs->id, 'cid' => $rs->cid, 'link' => $rs->customlink, 'dir' => $rs->catalogdir, 'domain' => $catalog[$rs->cid]['domain'], 'pubdate' => $rs->pubdate); $_iurlArray = array('mId' => $mId, 'id' => $rs->id, 'link' => $rs->customlink, 'dir' => $rs->catalogdir, 'pubdate' => $rs->pubdate); $iHtml = $this->iurl('show', $_iurlArray, $page - 1, iPATH); $rs->url = $this->iurl('content', $_urlArray); $tpl && $this->jumptohtml($iHtml, $rs->url); $rs->mid = $mId; $this->get['id'] = $rs->id; $this->get['title'] = $rs->title; if ($this->config['linkmode'] == 'id') { $this->iList($rs->cid, false); } elseif ($this->config['linkmode'] == 'title') { $this->iList($rs->catalogdir, false); } if ($this->config['ishtm']) { $rs->hits = "<script src=\"" . $this->config['url'] . "/action.php?do=hits&mid={$mId}&id={$rs->id}&action=show\" language=\"javascript\"></script>"; $rs->digg = "<script src=\"" . $this->config['url'] . "/action.php?do=digg&mid={$mId}&id={$rs->id}&action=show\" language=\"javascript\"></script>"; $rs->comments = "<script src=\"" . $this->config['url'] . "/action.php?do=comment&mid={$mId}&id={$rs->id}\" language=\"javascript\"></script>"; } if ($rs->tags) { $tagarray = explode(',', $rs->tags); if (count($tagarray) > 1) { foreach ($tagarray as $tk => $tag) { if ($this->chkTagVisible($tag)) { $rs->tag[$tk]['name'] = $tag; $rs->tag[$tk]['url'] = $this->config['url'] . '/tag.php?t=' . rawurlencode($tag) . '&mid=' . $mId; $rs->taglink .= '<a href="' . $rs->tag[$tk]['url'] . '" class="tag" target="_self">' . $rs->tag[$tk]['name'] . '</a> '; } } } else { if ($this->chkTagVisible($tagarray[0])) { $rs->tag[0]['name'] = $tagarray[0]; $rs->tag[0]['url'] = $this->config['url'] . '/tag.php?t=' . rawurlencode($tagarray[0]) . '&mid=' . $mId; $rs->taglink = '<a href="' . $this->config['url'] . '/tag.php?t=' . $rs->tag[0]['url'] . '" class="tag" target="_self">' . $tagarray[0] . '</a>'; } } } if ($fArray = explode(',', $model['field'])) { $SField = getSystemField(); $diff = array_diff_values($fArray, $SField); if ($diff['+']) { foreach ($rs as $field => $val) { if (in_array($field, $diff['+'])) { $FV = getFieldValue($mId, $field, $val); $FV !== Null && ($rs->{$field} = $FV); } } } } $prers = $this->db->getRow("SELECT * FROM `#iCMS@__{$__TABLE__}` WHERE `id` < '{$rs->id}' AND `cid`='{$rs->cid}' AND `visible`='1' order by id DESC Limit 1"); $rs->prev = $prers ? '<a href="' . $this->iurl('content', array('mId' => $mId, 'id' => $prers->id, 'cid' => $prers->cid, 'link' => $prers->customlink, 'dir' => $rs->catalogdir, 'domain' => $catalog[$rs->cid]['domain'], 'pubdate' => $prers->pubdate)) . '" class="prev" target="_self">' . $prers->title . '</a>' : $this->language('content:first'); $nextrs = $this->db->getRow("SELECT * FROM `#iCMS@__{$__TABLE__}` WHERE `id` > '{$rs->id}' and `cid`='{$rs->cid}' AND `visible`='1' order by id ASC Limit 1"); $rs->next = $nextrs ? '<a href="' . $this->iurl('content', array('mId' => $mId, 'id' => $nextrs->id, 'cid' => $nextrs->cid, 'link' => $nextrs->customlink, 'dir' => $rs->catalogdir, 'domain' => $catalog[$rs->cid]['domain'], 'pubdate' => $nextrs->pubdate)) . '" class="next" target="_self">' . $nextrs->title . '</a>' : $this->language('content:last'); $this->mode != 'CreateHtml' && $this->db->query("UPDATE `#iCMS@__{$__TABLE__}` SET hits=hits+1 WHERE `id` ='{$rs->id}' LIMIT 1"); $rs->link = "<a href='{$rs->selfurl}'>{$rs->title}</a>"; $this->result = $rs; $this->assign(array('id' => $rs->id, 'mid' => $rs->mid, 'selfurl' => $rs->selfurl, 'link' => $rs->link, 'title' => $rs->title, 'userid' => $rs->userid, 'postype' => $rs->postype, 'pubdate' => $rs->pubdate, 'hits' => $rs->hits, 'digg' => $rs->digg, 'comments' => $rs->comments, 'tag' => $rs->tag, 'taglink' => $rs->taglink, 'prev' => $rs->prev, 'next' => $rs->next)); $this->assign('content', (array) $rs); //3.1 所有内容 if ($tpl) { $tpl = empty($rs->tpl) ? $catalog[$rs->cid]['tpl_contents'] : $rs->tpl; return $this->iPrint($tpl, 'content'); } }
break; case 'updateHTML': empty($id) && alert("请选择要更新的内容"); include_once iPATH . "include/function/template.php"; MakeContentHtm($mid, $id) && alert('更新完成!', "url:1"); break; case 'del': !$id && alert("请选择要删除的内容"); delContent($mid, $id) && alert('成功删除!', "url:1"); break; case 'post': switch ($action) { case 'save': set_time_limit(0); //系统默认字段 $SystemField = getSystemField(); //字段定义 $__FIELD__ = $iCMS->cache('field.model', 'include/syscache', 0, true); $__MODEL__ = $iCMS->cache('model.id', 'include/syscache', 0, true); $id = $_POST['id']; $mid = $_POST['mid']; $table = $_POST['table']; $model = $__MODEL__[$mid]; $varArray = array(); if ($_POST['mVal']) { foreach ($_POST['mVal'] as $field => $value) { if (in_array($field, $SystemField)) { switch ($field) { case "userid": $value = $userid = intval($value); break;
function iCMS_model($vars, &$iCMS) { $cache = $iCMS->cache(array('catalog.cache', 'catalog.hidden', 'model.id', 'model.table', 'field.model'), 'include/syscache', 0, true); $cache['catalog.hidden'] && ($whereSQL .= GetIDSQL($cache['catalog.hidden'], 'cid', 'not')); if (isset($vars['mid'])) { $mId = (int) $vars['mid']; $model = $cache['model.id'][$mId]; $__TABLE__ = $model['table'] . '_content'; } elseif (isset($vars['name'])) { $model = $cache['model.table'][$vars['name']]; $mKey = array_keys($model); $mId = $mKey[0]; $model = $model[$mId]; $__TABLE__ = $vars['name'] . '_content'; } else { echo $iCMS->language('error:model.empty'); return; } if (empty($model)) { echo $iCMS->language('error:model.exit'); return; } if ($fArray = explode(',', $model['field'])) { $SField = getSystemField(); $diff = array_diff_values($fArray, $SField); } //---------------------------- $whereSQL = " visible='1'"; $maxperpage = isset($vars['row']) ? (int) $vars['row'] : 10; $cacheTime = isset($vars['time']) ? (int) $vars['time'] : -1; isset($vars['top']) && ($whereSQL .= " AND `top`='{$vars['top']}'"); $vars['call'] == 'user' && ($whereSQL .= " AND `postype`='0'"); $vars['call'] == 'admin' && ($whereSQL .= " AND `postype`='1'"); $catalog = $cache['catalog.cache']; if (isset($vars['sortid!'])) { $_NCID = TplCid($vars['sortid!']); $_NCID && ($NcIds[] = $_NCID); $vars['sub'] == 'all' && ($NcIds[] = $vars['sortid!']); $ids = $NcIds && $vars['sub'] == 'all' ? implode(',', $NcIds) : $vars['sortid!']; $whereSQL .= GetIDSQL($ids, 'cid', 'not'); } if (isset($vars['sortid'])) { $_CID = TplCid($vars['sortid']); $_CID && ($cIds[] = $_CID); $vars['sub'] == 'all' && ($cIds[] = $vars['sortid']); $ids = $cIds && $vars['sub'] == 'all' ? implode(',', $cIds) : $vars['sortid']; $whereSQL .= GetIDSQL($ids, '( cid') . " OR `vlink` REGEXP '[[:<:]]" . preg_quote(str_replace(',', '|', $ids), '/') . "[[:>:]]')"; } if (isset($vars['type'])) { if (strpos($vars['type'], ',')) { $vars['type'] = str_replace(',', '|', $vars['type']); $whereSQL .= " AND `type` REGEXP '[[:<:]]" . preg_quote($vars['type'], '/') . "[[:>:]]'"; } elseif (strpos($vars['type'], '&')) { $typeArray = explode('&', $vars['type']); foreach ($typeArray as $_type) { $whereSQL .= " AND `type` REGEXP '[[:<:]]" . preg_quote($_type, '/') . "[[:>:]]'"; } } else { $whereSQL .= " AND `type` REGEXP '[[:<:]]" . preg_quote($vars['type'], '/') . "[[:>:]]'"; } } $vars['id'] && ($whereSQL .= GetIDSQL($vars['id'], 'id')); $vars['id!'] && ($whereSQL .= GetIDSQL($vars['id!'], 'id', 'not')); $by = $vars['by'] == "ASC" ? "ASC" : "DESC"; // if($vars['keywords']){ // if(strpos($vars['keywords'],',')!==false){ // $kw=explode(',',$vars['keywords']); // foreach($kw AS $v){ // $keywords.=addslashes($v)."|"; // } // $keywords=substr($keywords,0,-1); // $whereSQL.= " And CONCAT(title,keywords,description) REGEXP '$keywords' "; // }else{ // $vars['keywords']=str_replace(array('%','_'),array('\%','\_'),$vars['keywords']); // $whereSQL.= " AND `keywords` like '%".addslashes($vars['keywords'])."%'"; // } // } if ($vars['action'] == 'search' || $vars['action'] == 'tag') { $whereSQL .= $iCMS->actionSQL; } switch ($vars['orderby']) { case "digg": $orderSQL = " ORDER BY `digg` {$by}"; break; case "hot": $orderSQL = " ORDER BY `hits` {$by}"; break; case "id": $orderSQL = " ORDER BY `id` {$by}"; break; case "comments": $orderSQL = " ORDER BY `comments` {$by}"; break; case "pubdate": $orderSQL = " ORDER BY `pubdate` {$by}"; break; case "disorder": $orderSQL = " ORDER BY `order`,`id` {$by}"; break; case "rand": $orderSQL = " ORDER BY rand() {$by}"; break; default: $orderSQL = " ORDER BY `id` {$by}"; } isset($vars['date']) && (list($iCMS->date['y'], $iCMS->date['m'], $iCMS->date['d']) = explode('-', $vars['date'])); if ($iCMS->date) { $day = empty($iCMS->date['d']) ? '01' : $iCMS->date['d']; $start = strtotime($iCMS->date['y'] . $iCMS->date['m'] . $day); $end = empty($iCMS->date['d']) ? $start + 84600 * $iCMS->date['total'] : $start + 84600; $whereSQL .= " AND `pubdate`<='{$end}' AND `pubdate`>='{$start}'"; } else { isset($vars['startdate']) && ($whereSQL .= " AND `pubdate`>='" . strtotime($vars['startdate']) . "'"); isset($vars['enddate']) && ($whereSQL .= " AND `pubdate`<='" . strtotime($vars['enddate']) . "'"); } isset($vars['where']) && ($whereSQL .= $vars['where']); $offset = 0; if ($vars['page']) { $total = $iCMS->db->getValue("SELECT count(*) FROM `#iCMS@__{$__TABLE__}` WHERE {$whereSQL} {$orderSQL}"); $pagenav = isset($vars['pagenav']) ? $vars['pagenav'] : "pagenav"; $pnstyle = isset($vars['pnstyle']) ? $vars['pnstyle'] : 0; $offset = $iCMS->multi(array('total' => $total, 'perpage' => $maxperpage, 'unit' => $iCMS->language('page:list'), 'url' => $iCMS->url, 'nowindex' => $GLOBALS['page'], 'pagenav' => $pagenav, 'pnstyle' => $pnstyle)); } if ($vars['cache'] == false || isset($vars['page'])) { $iCMS->config['iscache'] = false; $rs = ''; } else { $iCMS->config['iscache'] = true; $cacheName = 'model/' . md5($whereSQL . $orderSQL); $rs = $iCMS->cache($cacheName); } if (empty($rs)) { $rs = $iCMS->db->getArray("SELECT * FROM `#iCMS@__{$__TABLE__}` WHERE {$whereSQL} {$orderSQL} LIMIT {$offset} , {$maxperpage}"); // echo $iCMS->db->func_call; $_count = count($rs); for ($i = 0; $i < $_count; $i++) { $rs[$i]['sort']['name'] = $catalog[$rs[$i]['cid']]['name']; $rs[$i]['sort']['url'] = $rs['attr'] == 'page' ? $iCMS->iurl('page', array('link' => $catalog[$rs[$i]['cid']]['dir'], 'url' => $catalog[$rs[$i]['cid']]['url'], 'domain' => $catalog[$rs[$i]['cid']]['domain'])) : $iCMS->iurl('list', array('id' => $rs[$i]['cid'], 'link' => $catalog[$rs[$i]['cid']]['dir'], 'url' => $catalog[$rs[$i]['cid']]['url'], 'domain' => $catalog[$rs[$i]['cid']]['domain'])); $rs[$i]['sort']['link'] = "<a href='{$rs[$i]['sort']['url']}'>{$rs[$i]['sort']['name']}</a>"; $rs[$i]['url'] = $iCMS->iurl('content', array('mId' => $mId, 'id' => $rs[$i]['id'], 'cid' => $rs[$i]['cid'], 'link' => $rs[$i]['link'], 'url' => $rs[$i]['url'], 'dir' => $iCMS->cdir($catalog[$rs[$i]['cid']]), 'pubdate' => $rs[$i]['pubdate'], 'domain' => $catalog[$rs[$i]['cid']]['domain'])); $rs[$i]['link'] = "<a href='{$rs[$i]['url']}'>{$rs[$i]['title']}</a>"; if ($rs[$i]['tags'] && isset($vars['tags'])) { $tagarray = explode(',', $rs[$i]['tags']); if (count($tagarray) > 1) { foreach ($tagarray as $tag) { $iCMS->chkTagVisible($tag) && ($tags .= '<a href="' . $iCMS->config['url'] . '/tag.php?t=' . rawurlencode($tag) . '&mid=' . $mId . '" class="tag" target="_self">' . $tag . '</a> '); } } else { $iCMS->chkTagVisible($tagarray[0]) && ($tags = '<a href="' . $iCMS->config['url'] . '/tag.php?t=' . rawurlencode($tagarray[0]) . '&mid=' . $mId . '" class="tag" target="_self">' . $tagarray[0] . '</a>'); } $rs[$i]['tags'] = $tags; } if ($diff['+']) { foreach ($rs[$i] as $field => $val) { if (in_array($field, $diff['+'])) { $FV = getFieldValue($mId, $field, $val); $FV !== Null && ($rs[$i][$field] = $FV); } } } } $iCMS->cache(false)->addcache($cacheName, $rs, $cacheTime); } // var_dump($rs); return $rs; }