示例#1
0
 function dosave()
 {
     include_once iPATH . 'include/tag.class.php';
     $id = $_POST['id'];
     $mid = $_POST['mid'];
     $FArray = model::field($mid);
     $model = model::data($mid);
     $content = array();
     if ($_POST['content']) {
         foreach ($_POST['content'] as $field => $value) {
             if (model::isDefField($field)) {
                 switch ($field) {
                     case "userid":
                         $value = intval($value);
                         break;
                     case "fid":
                         $value = $fid = intval($value);
                         empty($value) && javascript::alert('请选择所属栏目');
                         break;
                     case "orderNum":
                         $value = _int($value);
                         break;
                     case "top":
                         $value = _int($value);
                         break;
                     case "title":
                         $value = dhtmlspecialchars($value);
                         empty($value) && javascript::alert('标题不能为空!');
                         break;
                     case "editor":
                         $value = dhtmlspecialchars($value);
                         break;
                     case "tags":
                         $value = iTAG::split(dhtmlspecialchars($value), true);
                         break;
                     case "type":
                         $value = intval($value);
                         break;
                     case "vlink":
                         $value = implode(',', $value);
                         break;
                     case "postype":
                         $value = empty($value) ? intval($value) : "1";
                         break;
                     case "pubdate":
                         $value = _strtotime($value);
                         break;
                     case "clink":
                         $value = dhtmlspecialchars($value);
                         if ($value) {
                             $clinklen = strlen($value);
                             for ($i = 0; $i < $clinklen; $i++) {
                                 !preg_match("/[a-zA-Z0-9_\\-~" . preg_quote($this->iCMS->config['CLsplit'], '/') . "]/", $value[$i]) && javascript::alert('自定链接只能由英文字母、数字或_-~组成(不支持中文)');
                             }
                         }
                         break;
                 }
             } elseif ($F = $FArray[$field]) {
                 switch ($F['type']) {
                     case "number":
                         $value = intval($value);
                         break;
                     case "calendar":
                         $value = _strtotime($value);
                         break;
                     case in_array($F['type'], array('text', 'textarea', 'radio', 'select', 'email', 'url', 'image', 'upload')):
                         $value = dhtmlspecialchars($value);
                         break;
                     case in_array($F['type'], array('checkbox', 'multiple')):
                         $value = implode(',', $value);
                         break;
                     case 'editor':
                         $this->iCMS->config['autoformat'] && ($value = autoformat($value));
                         break;
                     default:
                         $value = dhtmlspecialchars($value);
                 }
             }
             WordFilter($value) && javascript::alert($field . '字段包含被系统屏蔽的字符,请返回重新填写。');
             $content[$field] = $value;
             $PF[] = $field;
         }
     }
     if (empty($content['clink'])) {
         include iPATH . 'include/cn.class.php';
         $content['clink'] = CN::pinyin($content['title'], $this->iCMS->config['CLsplit']);
     }
     $table = model::tbn($_POST['table']);
     $MF = explode(',', $model['field']);
     $diff = array_diff_values($PF, $MF);
     if ($diff['-']) {
         foreach ($diff['-'] as $field) {
             $content[$field] = '';
         }
     }
     //缺少的字段 填认空值
     $SELFURL = __SELF__ . (empty($_POST['REFERER']) ? '?mo=content&do=manage' : $_POST['REFERER']);
     $forum = new forum();
     if (empty($id)) {
         empty($content['userid']) && ($content['userid'] = member::$uId);
         $content['hits'] = $content['good'] = $content['bad'] = $content['comments'] = 0;
         $content['status'] = "1";
         $checkCL = iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__{$table}` where `clink` ='" . $content['clink'] . "'");
         if ($this->iCMS->config['repeatitle']) {
             iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__{$table}` where `title` = '{$title}'") && alert('该标题内容已经存在!请检查是否重复');
             $checkCL && javascript::alert('该自定链接已经存在!请另选一个');
         } else {
             $checkCL && ($clink .= $this->iCMS->config['CLsplit'] . random(6, 1));
         }
         iCMS_DB::insert($table, $content);
         $id = iCMS_DB::$insert_id;
         model::upload($table, $id, $title);
         iTAG::add($content['tags'], $content['userid'], $id, $forum->rootid($fid), $mid);
         $vlink = empty($content['vlink']) ? $fid : $content['vlink'] . ',' . $fid;
         vlinkDiff($vlink, '', $id, $mid);
         if (!strstr($forum->forum[$fid]['contentRule'], '{PHP}') && !$forum->forum[$fid]['url'] && $forum->forum[$fid]['mode'] == "1" && $content['status']) {
             include iPATH . 'include/iHtml.class.php';
             iHtml::content($id, $mid, $table);
             iHtml::forum($fid, 1, 0, 1);
         }
         iCMS_DB::query("UPDATE `#iCMS@__forum` SET `count` = count+1 WHERE `fid` ='{$fid}' LIMIT 1 ");
         //			$moreaction=array(
         //				array("text"=>"编辑该内容","url"=>__SELF__."?do=content&operation=add&table=".$table."&mid=".$mid."&id=".$id),
         //				array("text"=>"继续添加内容","url"=>__SELF__."?do=content&operation=add&table=".$table."&mid=".$mid."&cid=".$cid),
         //				array("text"=>"查看该内容","url"=>$iCMS->iurl('content',array('mId'=>$mid,'id'=>$id,'link'=>$clink,'pubdate'=>$pubdate,'cid'=>$cid,'dir'=>$catalog->catalog[$cid]['dir'],'domain'=>$catalog->catalog[$cid]['domain'],'htmlext'=>$catalog->catalog[$cid]['htmlext']))->href,"o"=>'target="_blank"'),
         //				array("text"=>"查看网站首页","url"=>"../index.php","o"=>'target="_blank"')
         //			);
         javascript::dialog("添加完成!", 'url:' . __SELF__ . "?mo=content&do=manage&table=" . $table . "&mid=" . $mid);
     } else {
         $checkCL = iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__{$table}` where `clink` ='{$clink}' AND `id` !='{$id}'");
         if ($this->iCMS->config['repeatitle']) {
             $checkCL && alert('该自定链接已经存在!请另选一个');
         } else {
             $checkCL && ($clink .= $this->iCMS->config['CLsplit'] . random(6, 1));
         }
         $art = iCMS_DB::getRow("SELECT `fid`,`tags`,`vlink` FROM `#iCMS@__{$table}` where `id` ='{$id}'");
         iTAG::diff($content['tags'], member::$uId, $art->tags, $id, $forum->rootid($fid));
         iCMS_DB::update($table, $content, array('id' => $id));
         model::upload($table, $id, $title);
         $vlink = empty($content['vlink']) ? $fid : $content['vlink'] . ',' . $fid;
         vlinkDiff($vlink, $art->vlink, $id);
         if (!strstr($forum->forum[$fid]['contentRule'], '{PHP}') && !$forum->forum[$fid]['url'] && $forum->forum[$fid]['mode'] == "1" && $status) {
             include iPATH . 'include/iHtml.class.php';
             iHtml::content($id, $mid, $table);
             iHtml::forum($fid, 1, 0, 1);
         }
         if ($art->fid != $fid) {
             iCMS_DB::query("UPDATE `#iCMS@__forum` SET `count` = count-1 WHERE `fid` ='{$art->fid}' LIMIT 1 ");
             iCMS_DB::query("UPDATE `#iCMS@__forum` SET `count` = count+1 WHERE `fid` ='{$fid}' LIMIT 1 ");
         }
         javascript::dialog('编辑完成!<br />3秒后返回项目列表', 'url:' . $SELFURL);
     }
 }
示例#2
0
    if ($rs['hidden']) {
        ?>
[隐藏字段]<?php 
    }
    ?>
</td>
	      <td><?php 
    echo $rs['description'];
    ?>
</td>
	      <td>&lt;!--{$content.<?php 
    echo $rs['field'];
    ?>
}--&gt;</td>
	      <td><?php 
    if (!model::isDefField($rs['field'])) {
        ?>
	        <a href="<?php 
        echo __ADMINCP__;
        ?>
=models&do=addfield&id=<?php 
        echo $rs['mid'];
        ?>
&fid=<?php 
        echo $rs['id'];
        ?>
">编辑</a> |
	        <a href="<?php 
        echo __ADMINCP__;
        ?>
=models&do=delfield&id=<?php 
示例#3
0
function form($A, $rs = array(), $isUser = false)
{
    $id = $A['field'];
    $val = $rs[$id] ? $rs[$id] : '';
    $mId = $rs['mid'];
    $mName = $rs['mName'];
    $option = unserialize($A['option']);
    $optStr = $option[$A['type']];
    if ($optStr) {
        $_optArray = explode("\n", $optStr);
        foreach ($_optArray as $k => $optA) {
            list($index, $choice) = explode("=", $optA);
            $optArray[trim($index)] = trim($choice);
        }
    }
    if ($A['hidden']) {
        $FORM['hidden'] = '<input type="hidden" name="content[' . $id . ']" id="' . $id . '" value="' . $val . '" />';
    } else {
        //判读是否为特殊字段
        if (in_array($A['field'], array('fid', 'type', 'vlink'))) {
            switch ($A['field']) {
                case "fid":
                    $forum = new forum();
                    $cata_option = $isUser ? $forum->user_select($val, 0, 1, 1, $mId) : $forum->select($val, 0, 1, NULL, $mId);
                    if ($cata_option) {
                        $html = '<select name="content[fid]" id="fid" style="width:auto;">';
                        $html .= '<option value="0"> == 请选择所属栏目 == </option>';
                        $html .= $cata_option;
                    } else {
                        if ($isUser) {
                            $html = '<select name="content[fid]" id="fid">';
                            $html .= '<option value="0"> == 暂无栏目 == </option>';
                        } else {
                            $html = '<select name="content[fid]" id="fid" onclick="window.location.replace(\'' . __ADMINCP__ . '=forums&do=add\');">';
                            $html .= '<option value="0"> == 暂无栏目请先添加 == </option>';
                        }
                    }
                    $html .= '</select>';
                    break;
                case "type":
                    $html = '<select name="content[type]"id="type">';
                    $html .= '<option value="0">默认属性[type=\'0\']</option>';
                    $html .= contentype($mName, $val);
                    $html .= '</select>';
                    break;
                case "vlink":
                    $forum = new forum();
                    $html = '<select name="content[vlink][]" size="10" multiple="multiple" id="vlink">';
                    $html .= $isUser ? $forum->user_select($val, 0, 1, 1, $mId) : $forum->select($val, 0, 1, 'all', $mId);
                    $html .= '</select>';
                    $html .= selected($val, 'vlink', 'js');
                    break;
                    //	case in_array($A['field'],array('hits','digg','comments','status','postype')):	break;
            }
        } else {
            switch ($A['type']) {
                case in_array($A['type'], array('number', 'text', 'email', 'url')):
                    $html = '<input type="text" name="content[' . $id . ']" class="txt" id="' . $id . '" value="' . $val . '" />';
                    break;
                case "radio":
                    foreach ((array) $optArray as $value => $text) {
                        $checked = $value == $val ? ' checked="checked"' : '';
                        $html .= ' <input type="radio" name="content[' . $id . ']" class="radio" id="' . $id . '" value="' . $value . '" /> ' . $text;
                    }
                    break;
                case "checkbox":
                    $valArray = explode(',', $val);
                    foreach ((array) $optArray as $value => $text) {
                        $checked = in_array($value, $valArray) ? ' checked="checked"' : '';
                        $html .= ' <input type="checkbox" name="content[' . $id . '][]" class="checkbox" id="' . $id . '.' . $value . '" value="' . $value . '" ' . $checked . '/> ' . $text;
                    }
                    break;
                case "textarea":
                    $html = '<textarea name="content[' . $id . ']" id="' . $id . '" onKeyUp="textareasize(this)" class="tarea">' . $val . '</textarea>';
                    break;
                    //				case "editor":
                    //					$html='<script type="text/javascript" src="editor/fckeditor.js"></script>
                    //<script type="text/javascript" src="admin/js/plus_format_fck.js"></script><select class="BP">
                    //            <option value="1">第 1 页</option>
                    //          </select><input type="button" value="新增一页" onClick="newBody();" class="button">
                    //<iframe id="rtf" style="width: 0px; height: 0px;" marginwidth="0" marginheight="0" src="about:blank" scrolling="no"></iframe>
                    //          <label for="x_paste"></label>
                    //          <script>rtf.document.designMode="On";</script>
                    //          <input type="button" name="formatbutton" value="粘贴排版" onclick="trans(iCMS.eId);" class="button">
                    //          <input type="button" name="formatbutton_img" value="自动排版" onClick="FormatImages(iCMS.eId)" class="button">
                    //          <input type="button" value="批量上传" onClick="multiUpload();" class="button">
                    //          <input type="button" value="插入图片" onClick="iCMS.showDialog(\''.__ADMINCP__.'=dialog&do=file&click=file&type=gif,jpg,png,bmp,jpeg&from=editor\',\'iCMSEDITOR\',\'从网站选择\');" class="button">
                    //<div id="iBody_1" class="nb">
                    //            <textarea id="iEditor_1" name="content['.$id.'][]" cols="80" rows="20" style="display:none">'.$val.'</textarea>
                    //            <input type="hidden" id="iEditor_1___Config" value="" style="display:none" />
                    //            <iframe id="iEditor_1___Frame" src="./editor/fckeditor.html?InstanceName=iEditor_1&amp;Toolbar=Default" width="100%" height="500" frameborder="0" scrolling="no"></iframe>
                    //          </div>';
                    //				break;
                //				case "editor":
                //					$html='<script type="text/javascript" src="editor/fckeditor.js"></script>
                //<script type="text/javascript" src="admin/js/plus_format_fck.js"></script><select class="BP">
                //            <option value="1">第 1 页</option>
                //          </select><input type="button" value="新增一页" onClick="newBody();" class="button">
                //<iframe id="rtf" style="width: 0px; height: 0px;" marginwidth="0" marginheight="0" src="about:blank" scrolling="no"></iframe>
                //          <label for="x_paste"></label>
                //          <script>rtf.document.designMode="On";</script>
                //          <input type="button" name="formatbutton" value="粘贴排版" onclick="trans(iCMS.eId);" class="button">
                //          <input type="button" name="formatbutton_img" value="自动排版" onClick="FormatImages(iCMS.eId)" class="button">
                //          <input type="button" value="批量上传" onClick="multiUpload();" class="button">
                //          <input type="button" value="插入图片" onClick="iCMS.showDialog(\''.__ADMINCP__.'=dialog&do=file&click=file&type=gif,jpg,png,bmp,jpeg&from=editor\',\'iCMSEDITOR\',\'从网站选择\');" class="button">
                //<div id="iBody_1" class="nb">
                //            <textarea id="iEditor_1" name="content['.$id.'][]" cols="80" rows="20" style="display:none">'.$val.'</textarea>
                //            <input type="hidden" id="iEditor_1___Config" value="" style="display:none" />
                //            <iframe id="iEditor_1___Frame" src="./editor/fckeditor.html?InstanceName=iEditor_1&amp;Toolbar=Default" width="100%" height="500" frameborder="0" scrolling="no"></iframe>
                //          </div>';
                //				break;
                case "editor":
                    global $iCMS;
                    include iPATH . "include/fckeditor.php";
                    $editor = new FCKeditor('content[' . $id . ']');
                    $editor->BasePath = $iCMS->config['publicURL'];
                    $editor->ToolbarSet = $isUser ? 'User' : 'Default';
                    $editor->Value = $val;
                    //$html='<script type="text/javascript" src="'.$iCMS->config['publicURL'].'/ui/editor/fckeditor.js"></script>';
                    $html = $editor->CreateHtml();
                    break;
                case "select":
                    $html = '<select name="content[' . $id . ']" id="' . $id . '" style="width:auto;">';
                    $html .= '<option value="0"> == 不选择 == </option>';
                    foreach ((array) $optArray as $value => $text) {
                        $selected = $value == $val ? ' selected="selected"' : '';
                        $html .= '<option value="' . $value . '"' . $selected . '>' . $text . '</option>';
                    }
                    $html .= '</select>';
                    break;
                case "multiple":
                    $html = '<select name="content[' . $id . '][]" id="' . $id . '" style="width:auto;" size="10" multiple="multiple">';
                    $html .= '<option value="0"> == 不选择 == </option>';
                    $valArray = explode(',', $val);
                    foreach ((array) $optArray as $value => $text) {
                        $selected = in_array($value, $valArray) ? ' selected="selected"' : '';
                        $html .= '<option value="' . $value . '"' . $selected . '>' . $text . '</option>';
                    }
                    $html .= '</select>';
                    break;
                case "calendar":
                    $html = '<input name="content[' . $id . ']" class="txt datepicker" value="' . get_date($val, 'Y-m-d H:i:s') . '" id="' . $id . '" type="text"/>';
                    break;
                    //				case "image":
                    //					$html='<input name="content['.$id.']" id="image_'.$id.'" type="text" value="'.$val.'" class="txt" style="width:450px"/>';
                    //					$html.='<button type="button" class="selectdefault button" hidefocus=true to="image_'.$id.'"><span>选 择</span></button>';
                    //					$html.='<div id="image_'.$id.'_menu" style="display:none;">';
                    //					$html.='<ul>';
                    //					$html.='<li onClick="iCMS.showDialog(\''.__ADMINCP__.'=dialog&do=Aupload\',\'image_'.$id.'\',\'本地上传\',400,150);">本地上传</li>';
                    //					$html.='<li onClick="iCMS.showDialog(\''.__ADMINCP__.'=dialog&do=file&click=file&type=gif,jpg,png,bmp,jpeg\',\'image_'.$id.'\',\'从网站选择\');">从网站选择</li>';
                    //					$html.='<li onClick="viewPic(\'image_'.$id.'\');">查看缩略图</li>';
                    //					$html.='<li onClick="crop(\'image_'.$id.'\');">剪裁图片</li>';
                    //					$html.='</ul></div>';
                    //				break;
                //				case "image":
                //					$html='<input name="content['.$id.']" id="image_'.$id.'" type="text" value="'.$val.'" class="txt" style="width:450px"/>';
                //					$html.='<button type="button" class="selectdefault button" hidefocus=true to="image_'.$id.'"><span>选 择</span></button>';
                //					$html.='<div id="image_'.$id.'_menu" style="display:none;">';
                //					$html.='<ul>';
                //					$html.='<li onClick="iCMS.showDialog(\''.__ADMINCP__.'=dialog&do=Aupload\',\'image_'.$id.'\',\'本地上传\',400,150);">本地上传</li>';
                //					$html.='<li onClick="iCMS.showDialog(\''.__ADMINCP__.'=dialog&do=file&click=file&type=gif,jpg,png,bmp,jpeg\',\'image_'.$id.'\',\'从网站选择\');">从网站选择</li>';
                //					$html.='<li onClick="viewPic(\'image_'.$id.'\');">查看缩略图</li>';
                //					$html.='<li onClick="crop(\'image_'.$id.'\');">剪裁图片</li>';
                //					$html.='</ul></div>';
                //				break;
                case "upload":
                    $html = '<div id="' . $id . '1" style="display:' . ($val ? 'none' : 'block') . ';"><input id="' . $id . 'file" name="content_upload_' . $id . '" type="file" style="width:600px;" /><span id="c' . $id . '1" style="display:' . ($val ? '' : 'none') . '">[<a href="javascript:iCMS.SH(\'' . $id . '2\',\'' . $id . '1\');">取消</a>]</span></div>
          		<div id="' . $id . '2" style="display:' . ($val ? 'block' : 'none') . '"><a class="content_viewPic" ref="' . $id . '" href="javascript:void(0);" title="点击查看图片">' . $val . '</a><input name="content[' . $id . ']" type="text" value="' . $val . '" class="txt content_upload_' . $id . '" style="display:none;"/> [<a href="javascript:iCMS.SH(\'' . $id . '1\',\'' . $id . '2\');">重新上传</a>] [<a href="' . ($isUser ? __USERCP__ : __ADMINCP__) . '=content&do=delpic&mid=' . $mId . '&table=' . $mName . '&id=' . $rs['id'] . '&field=' . $id . '&fp=' . $val . '" target="iCMS_FRAME">删除</a>]</div><script type="text/javascript">	$(".content_viewPic").click(function(){
		var path	=$(\'.content_upload_\'+$(this).attr(\'ref\')).val();
		iCMS.showDialog("' . ($isUser ? __USERCP__ : __ADMINCP__) . '=dialog&do=viewPic",path,\'查看图片\');
	});</script>';
                    break;
            }
        }
        if ($A['show'] || !$isUser) {
            $FORM['general'] = array('id' => $id, 'label' => $A['name'], 'description' => $A['description'], 'html' => $html);
        }
    }
    if (!model::isDefField($id)) {
        $valal = '$("#' . $id . '").val()';
        //验证
        switch ($A['validate']) {
            case "0":
                //不能为空
                if ($A['type'] == "editor") {
                    $js = 'var ' . $id . '_Editor = FCKeditorAPI.GetInstance(\'content[' . $id . ']\') ;
					if(' . $id . '_Editor.GetXHTML( true )==""){
						alert("' . $A['name'] . '不能为空!");
						' . $id . '_Editor.focus();
						return false;
					}';
                } else {
                    $js = 'if(' . $valal . '==""){
					alert("' . $A['name'] . '不能为空!");
					$("#' . $id . '").focus();
					return false;}';
                }
                break;
            case "2":
                $js = 'var ' . $id . '_val = ' . $valal . ';
					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 = ' . $valal . ';
					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 = ' . $valal . ';
					var pattern = /^[a-zA-z]+:\\/\\/[^\\s]*/;
					if(!pattern.test(' . $id . '_val)){
						alert("[' . $A['name'] . ']网址格式不正确!!");
						$("#' . $id . '").focus();
						return false;}';
                break;
        }
    }
    if ($A['show'] || !$isUser) {
        $FORM['js'] = $js;
    }
    //	var_dump($FORM);
    //	var_dump($A);
    return $FORM;
}
示例#4
0
 function doEditField()
 {
     $fid = (int) $_POST['fid'];
     $mid = (int) $_POST['mid'];
     $name = dhtmlspecialchars($_POST['name']);
     $field = dhtmlspecialchars($_POST['field']);
     $ofield = dhtmlspecialchars($_POST['ofield']);
     if (empty($field)) {
         include iPATH . 'include/cn.class.php';
         $field = CN::pinyin($name);
     }
     $type = $_POST['type'];
     $show = $_POST['show'];
     $default = dhtmlspecialchars($_POST['default']);
     $validate = $_POST['validate'];
     $description = dhtmlspecialchars($_POST['description']);
     $option = addslashes(serialize($_POST['option']));
     $hidden = isset($_POST['hidden']) ? 1 : 0;
     !preg_match("/[a-zA-Z]/", $field[0]) && javascript::alert('字段只能以英文字母开头');
     !preg_match("/[a-zA-Z0-9_\\-~]/", $field) && javascript::alert('字段只能由英文字母或数字组成');
     model::isDefField($field) && javascript::alert('您所填写的字段是默认字段!请重新填写.');
     $model = model::data($mid);
     $oFieldA = explode(',', $model['field']);
     $sql = "ALTER TABLE `#iCMS@__" . model::tbn($model['table']) . "`";
     if ($fid) {
         iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__field` where `field` = '{$field}' and `mid`='{$mid}' and `id`!='{$fid}'") && javascript::alert('该字段已经存在!请检查是否重复');
         iCMS_DB::query("UPDATE `#iCMS@__field` SET `name` = '{$name}', `field` = '{$field}', `mid` = '{$mid}', `type` = '{$type}',`show` = '{$show}', `default` = '{$default}', `validate` = '{$validate}', `hidden` = '{$hidden}', `description` = '{$description}', `option` = '{$option}' WHERE `id` = '{$fid}';");
         $sql .= " CHANGE COLUMN `{$ofield}` `{$field}`";
         if ($field != $ofield) {
             $fKey = array_search($ofield, $oFieldA);
             unset($oFieldA[$fKey]);
         }
     } else {
         iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__field` where `field` = '{$field}' and `mid`='{$mid}'") && javascript::alert('该字段已经存在!请检查是否重复');
         iCMS_DB::query("INSERT INTO `#iCMS@__field` (`name`, `field`, `mid`, `type`,`show`, `default`, `validate`, `hidden`, `description`, `option`) VALUES ('{$name}', '{$field}', '{$mid}', '{$type}', '{$show}', '{$default}', '{$validate}', '{$hidden}', '{$description}', '{$option}');");
         $sql .= " ADD COLUMN `{$field}`";
         //新增
         $col = iCMS_DB::getCol("describe `#iCMS@__" . model::tbn($model['table']) . "`");
         $AfterSql = ' after `' . end($col) . '`';
     }
     $SqlType = model::SqlType($type, $default);
     iCMS_DB::query($sql . $SqlType . $AfterSql);
     if ($field != $ofield) {
         array_push($oFieldA, $field);
         $mField = implode(',', array_unique($oFieldA));
         iCMS_DB::query("update `#iCMS@__model` SET `field`='{$mField}' where id='{$mid}'");
     }
     model::cache();
     javascript::dialog('字段添加完成!<br />10秒后返回字段管理', "url:" . __SELF__ . "?mo=models&do=managefield&id=" . $mid);
 }
示例#5
0
 function content($id, $mId, $table = NULL, $tpl = true)
 {
     $model = $this->getCache('system/models.cache', $mId);
     empty($table) && ($table = $model['tbn']);
     $rs = iCMS_DB::getRow("SELECT * FROM `#iCMS@__{$table}` WHERE id='" . (int) $id . "' AND `status` ='1'");
     empty($rs) && $this->error('error:page');
     $F = $this->getCache('system/forum.cache', $rs->fid);
     if ($F['status'] == 0) {
         return false;
     }
     if ($rs->url) {
         if ($this->mode == "CreateHtml") {
             return false;
         } else {
             $this->go($rs->url);
         }
     }
     if ($this->mode == "CreateHtml" && (strstr($F['contentRule'], '{PHP}') || $F['url'] || $F['mode'] == 0)) {
         return false;
     }
     $_iurlArray = array((array) $rs, $F, $model);
     $rs->iurl = $this->iurl('content', $_iurlArray, $page);
     $rs->url = $rs->iurl->href;
     $tpl && $this->gotohtml($rs->iurl->path, $rs->iurl->href, $F['mode']);
     $this->iList($rs->fid, false);
     $rs->comment = array('url' => $this->config['publicURL'] . "/comment.php?indexId={$rs->id}&mId={$mId}&sortId={$rs->fid}", 'count' => $rs->comments);
     if ($F['mode']) {
         $rs->hits = "<script type=\"text/javascript\" src=\"" . $this->config['publicURL'] . "/action.php?do=hits&mid={$mId}&fid={$rs->fid}&id={$rs->id}&action=show\" language=\"javascript\"></script>";
         $rs->digg = "<script type=\"text/javascript\" src=\"" . $this->config['publicURL'] . "/action.php?do=digg&mid={$mId}&id={$rs->id}&action=show\" language=\"javascript\"></script>";
         $rs->comments = "<script type=\"text/javascript\" src=\"" . $this->config['publicURL'] . "/action.php?do=comment&mid={$mId}&id={$rs->id}&action=show\" language=\"javascript\"></script>";
     } else {
         $this->mode != 'CreateHtml' && iCMS_DB::query("UPDATE `#iCMS@__{$table}` SET hits=hits+1 WHERE `id` ='{$rs->id}' LIMIT 1");
     }
     if ($rs->tags) {
         $tagarray = explode(',', $rs->tags);
         foreach ($tagarray as $tk => $tag) {
             $t = $this->getTag($tag);
             if ($t) {
                 $rs->tag[$tk]['name'] = $tag;
                 $rs->tag[$tk]['url'] = $t['url']->href;
                 $rs->taglink .= '<a href="' . $rs->tag[$tk]['url'] . '" class="tag" target="_self" title="' . $t['count'] . $this->language('page:list') . '">' . $rs->tag[$tk]['name'] . '</a> ';
             }
         }
     }
     if ($fArray = explode(',', $model['field'])) {
         include_once iPATH . 'include/model.class.php';
         foreach ($fArray as $k => $field) {
             if (!model::isDefField($field)) {
                 $FV = model::FieldValue($mId, $field, $rs->{$field});
                 $FV !== Null && ($rs->{$field} = $FV);
             }
         }
     }
     $rs->prev = $this->language('show:first');
     $prers = iCMS_DB::getRow("SELECT * FROM `#iCMS@__{$table}` WHERE `id` < '{$rs->id}' AND `fid`='{$rs->fid}' AND `status`='1' order by id DESC Limit 1");
     $prers && ($rs->prev = '<a href="' . $this->iurl('content', array((array) $prers, $F, $model))->href . '" class="prev" target="_self">' . $prers->title . '</a>');
     $rs->next = $this->language('show:last');
     $nextrs = iCMS_DB::getRow("SELECT * FROM `#iCMS@__{$table}` WHERE `id` > '{$rs->id}'  and `fid`='{$rs->fid}' AND `status`='1' order by id ASC Limit 1");
     $nextrs && ($rs->next = '<a href="' . $this->iurl('content', array((array) $nextrs, $F, $model))->href . '" class="next" target="_self">' . $nextrs->title . '</a>');
     $rs->link = "<a href='{$rs->url}'>{$rs->title}</a>";
     $rs->mid = $mId;
     $rs->table = $table;
     $this->Hook($rs);
     $this->assign('content', (array) $rs);
     if ($tpl) {
         $tpl = empty($rs->tpl) ? $F['contentTPL'] : $rs->tpl;
         return $this->iPrint($tpl, 'content');
     }
 }
示例#6
0
function iCMS_contents($vars, &$iCMS)
{
    if (isset($vars['mid'])) {
        $mId = (int) $vars['mid'];
        $model = $iCMS->getCache('system/models.cache', $mId);
        $table = $model['tbn'];
    } elseif (isset($vars['name'])) {
        $model = $iCMS->getCache('system/models.table', $vars['name']);
        $mId = $model['id'];
        $table = $model['tbn'];
    } else {
        if (isset($iCMS->metadata)) {
            $mId = $iCMS->metadata->mid;
            $table = $iCMS->metadata->table;
            $model = $iCMS->getCache('system/models.cache', $mId);
        } else {
            echo $iCMS->language('error:model.empty');
            return;
        }
    }
    if (empty($model)) {
        echo $iCMS->language('error:model.exit');
        return;
    }
    //----------------------------
    $whereSQL = " status='1'";
    $_cache = $iCMS->getCache(array('system/forum.cache', 'system/forum.hidden'));
    $_cache['system/forum.hidden'] && ($whereSQL .= getSQL($_cache['system/forum.hidden'], 'fid', 'not'));
    $maxperpage = isset($vars['row']) ? (int) $vars['row'] : 10;
    $cacheTime = isset($vars['time']) ? (int) $vars['time'] : -1;
    isset($vars['userid']) && ($whereSQL .= " AND `userid`='{$vars['userid']}'");
    isset($vars['author']) && ($whereSQL .= " AND `author`='{$vars['author']}'");
    isset($vars['top']) && ($whereSQL .= " AND `top`='" . _int($vars['top']) . "'");
    $vars['call'] == 'user' && ($whereSQL .= " AND `postype`='0'");
    $vars['call'] == 'admin' && ($whereSQL .= " AND `postype`='1'");
    $forum = $_cache['system/forum.cache'];
    if (isset($vars['fid!'])) {
        $_Nfid = getfids($vars['fid!']);
        $_Nfid && ($Nfids[] = $_Nfid);
        $vars['sub'] == 'all' && ($Nfids[] = $vars['fid!']);
        $ids = $Nfids && $vars['sub'] == 'all' ? implode(',', $Nfids) : $vars['fid!'];
        $whereSQL .= getSQL($ids, 'fid', 'not');
    }
    if (isset($vars['fid'])) {
        $_fid = getfids($vars['fid']);
        $_fid && ($fids[] = $_fid);
        $vars['sub'] == 'all' && ($fids[] = $vars['fid']);
        $ids = $fids && $vars['sub'] == 'all' ? implode(',', $fids) : $vars['fid'];
        $whereSQL .= getSQL($ids, 'fid');
    }
    isset($vars['type']) && ($whereSQL .= " AND `type` ='{$vars['type']}'");
    $vars['id'] && ($whereSQL .= getSQL($vars['id'], 'id'));
    $vars['id!'] && ($whereSQL .= getSQL($vars['id!'], 'id', 'not'));
    $by = $vars['by'] == "ASC" ? "ASC" : "DESC";
    switch ($vars['orderby']) {
        case "id":
            $orderSQL = " ORDER BY `id` {$by}";
            break;
        case "hot":
            $orderSQL = " ORDER BY `hits` {$by}";
            break;
        case "comment":
            $orderSQL = " ORDER BY `comments` {$by}";
            break;
        case "pubdate":
            $orderSQL = " ORDER BY `pubdate` {$by}";
            break;
        case "disorder":
            $orderSQL = " ORDER BY `orderNum` {$by}";
            break;
            //        case "rand":    $orderSQL=" ORDER BY rand() $by";    break;
        //        case "rand":    $orderSQL=" ORDER BY rand() $by";    break;
        case "top":
            $orderSQL = " ORDER BY `top`,`orderNum` ASC";
            break;
        default:
            $orderSQL = " ORDER BY `id` DESC";
    }
    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 + 86400 * $iCMS->date['total'] : $start + 86400;
        $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']);
    if ($vars['action'] == 'search') {
        $whereSQL .= $iCMS->actionSQL;
    } elseif ($vars['action'] == 'tag') {
        if (empty($vars['tag'])) {
            return false;
        }
        if (is_array($vars['tag'])) {
            $_tCache = $vars['tag'];
        } else {
            $_tCache = $iCMS->getCache($iCMS->getTagKey($vars['tag']));
        }
        if ($_tCache['id']) {
            $tidSQL = 'AND `tid`=\'' . $_tCache['id'] . '\'';
        } else {
            if ($_tCache) {
                foreach ($_tCache as $_tag) {
                    if ($_tag) {
                        $_tids[] = $_tag['id'];
                    }
                }
            }
            if (empty($_tids)) {
                return false;
            }
            $tidSQL = 'AND `tid` in (' . implode(',', $_tids) . ')';
        }
        $countSQL = 'SELECT count(#iCMS@__' . $table . '.id) FROM `#iCMS@__' . $table . '`,`#iCMS@__taglist` WHERE #iCMS@__' . $table . '.id = `indexId` ' . $tidSQL . ' AND  #iCMS@__taglist.modelId=' . $mId . ' AND';
        $selectSQL = 'SELECT #iCMS@__' . $table . '.* FROM `#iCMS@__' . $table . '`,`#iCMS@__taglist` WHERE #iCMS@__' . $table . '.id = `indexId` ' . $tidSQL . ' AND #iCMS@__taglist.modelId=' . $mId . ' AND';
        $orderSQL = " ORDER BY #iCMS@__taglist.indexId {$by}";
        $vars['indexId!'] && ($whereSQL .= getSQL($vars['indexId!'], '#iCMS@__' . $table . '.id', 'not'));
    }
    $offset = 0;
    if ($vars['page']) {
        empty($countSQL) && ($countSQL = "SELECT count(*) FROM `#iCMS@__{$table}` WHERE");
        $total = iCMS_DB::getValue($countSQL . " {$whereSQL}");
        //        echo iCMS_DB::last_query;
        $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'), 'nowindex' => $GLOBALS['page'], 'pagenav' => $pagenav, 'pnstyle' => $pnstyle));
        //        $GLOBALS['cpn'] && $iCMS->_vars['pagenav'].='<span><a class="page_more" href="more.php?fid='.$ids.'" target="_self">'.$iCMS->language('page:more').'</a></span>';
        //$iCMS->addto($pagenav,"----------------");
    }
    $iscache = true;
    if ($vars['cache'] == false || isset($vars['page'])) {
        $iscache = false;
        $rs = array();
    } else {
        $cacheName = 'clist/' . md5($whereSQL . $orderSQL . $maxperpage);
        $rs = $iCMS->getCache($cacheName);
    }
    if (empty($rs)) {
        empty($selectSQL) && ($selectSQL = "SELECT * FROM `#iCMS@__{$table}` WHERE");
        $rs = iCMS_DB::getArray($selectSQL . " {$whereSQL} {$orderSQL} LIMIT {$offset} , {$maxperpage}");
        //echo iCMS_DB::$last_query;
        //iCMS_DB::$last_query='explain '.iCMS_DB::$last_query;
        //$explain=iCMS_DB::getRow(iCMS_DB::$last_query);
        //print_r($explain);
        $_count = count($rs);
        for ($i = 0; $i < $_count; $i++) {
            $F = $forum[$rs[$i]['fid']];
            $rs[$i]['sort']['name'] = $F['name'];
            $rs[$i]['sort']['url'] = $iCMS->iurl('forum', $F)->href;
            $rs[$i]['sort']['link'] = "<a href='{$rs[$i]['sort']['url']}'>{$rs[$i]['sort']['name']}</a>";
            $rs[$i]['url'] = $iCMS->iurl('content', array($rs[$i], $F, $model))->href;
            $rs[$i]['commentUrl'] = $iCMS->config['publicURL'] . "/comment.php?indexId=" . $rs[$i]['id'] . "&mId=" . $mId . "&sortId=" . $rs[$i]['fid'];
            $rs[$i]['link'] = "<a href='{$rs[$i]['url']}'>{$rs[$i]['title']}</a>";
            if ($rs[$i]['tags'] && isset($vars['tag'])) {
                $tagarray = explode(',', $rs[$i]['tags']);
                foreach ($tagarray as $tk => $tag) {
                    $t = $iCMS->getTag($tag);
                    if ($t) {
                        $rs[$i]['tag'][$tk]['name'] = $tag;
                        $rs[$i]['tag'][$tk]['url'] = $t['url']->href;
                        $rs[$i]['taglink'] .= '<a href="' . $rs[$i]['tag'][$tk]['url'] . '" class="tag" target="_self">' . $tag . '</a> ';
                    }
                }
            }
            if ($fArray = explode(',', $model['field'])) {
                foreach ($fArray as $k => $field) {
                    if (!model::isDefField($field)) {
                        $FV = model::FieldValue($mId, $field, $rs[$i][$field]);
                        $FV !== Null && ($rs[$i][$field] = $FV);
                    }
                }
            }
        }
        $iscache && $iCMS->SetCache($cacheName, $rs, $cacheTime);
    }
    //	var_dump($rs);
    return $rs;
}