Ejemplo n.º 1
0
 public function actionIndex()
 {
     $rows = CDB()->from('configs')->queryAll();
     if ($rows) {
         foreach ($rows as $v) {
             $data[$v['name']] = $v['body'];
         }
     }
     if ($_POST['config']) {
         $config = $_POST['config'];
         if ($config) {
             CDB()->update('configs', array('body' => ""));
             foreach ($config as $k => $v) {
                 $row = CDB()->from('configs')->where("name=:name", array(':name' => $k))->queryRow();
                 if (!$row) {
                     CDB()->insert('configs', array('name' => $k, 'body' => $v));
                 } else {
                     CDB()->update('configs', array('body' => $v), "name=:name", array(':name' => $k));
                 }
             }
             flash('success', __('success'));
             cache('config', false);
             $this->refresh();
         }
     }
     $this->render('index', $data);
 }
Ejemplo n.º 2
0
 public function actionView()
 {
     $id = (int) $_GET['id'];
     if ($id > 0) {
         $row = CDB()->from('videos')->where('id=:id', array(':id' => $id))->queryRow();
         $this->render('view', $row);
     }
 }
Ejemplo n.º 3
0
 static function attachment($fid)
 {
     $d = cache('attachments_' . $fid);
     if (!$d) {
         $row = CDB()->from('attachments')->where("id=:id", array(':id' => $fid))->queryRow();
         $d = array('name' => $row['name'], 'fullpath' => $row['fullpath']);
         cache('attachments_' . $fid, $d);
     }
     return $d;
 }
Ejemplo n.º 4
0
 function action($name, $model, $v)
 {
     if ($v) {
         if (is_array($v)) {
         } else {
             $value = CDB()->from('attachments')->where('id=:id', array(':id' => $v))->queryAll();
         }
     }
     $name = "AutoModel[{$name}]";
     echo widget('plupload', array('field' => $name, 'multi' => false, 'values' => $value));
 }
Ejemplo n.º 5
0
 public function actionSort()
 {
     $ids = $sort = $_POST['ids'];
     arsort($sort);
     $sort = array_merge($sort, array());
     $table = "album_images";
     $fid = $id;
     foreach ($ids as $k => $id) {
         CDB()->update($table, array('sort' => $sort[$k]), 'id=:id', array(':id' => $id));
     }
     return 1;
 }
Ejemplo n.º 6
0
 function run()
 {
     $result = CDB()->from('attachments');
     $posts = CDB()->from('attachments');
     $pager = new PagerHelper($result, $posts);
     $pager->pageSize = 5;
     $pager = $pager->run();
     if (true === Yii::app()->request->isAjaxRequest) {
         Yii::app()->controller->layout = false;
     }
     js_code("\n\t\t\tfunction ajax_body_insert(){\n\t\t\t\t\$('#ajax_body img').click(function(){  \n\t\t\t\t\tvar rel = \$(this).attr('rel'); \n\t\t\t\t\t" . $this->tag . ".insertHtml('<img src='+rel+' />');\n\t\t\t\t\t\$('#ajax_body #up').fadeIn().fadeOut(2000);\n\t\t\t\t}); \n\t\t\t}\n\t\t\tajax_body_insert();\n\t\t\tfunction ajaxPager(){\n\t\t\t\t\$('#ajaxPager a').click(function(){ \n\t\t\t\t\tvar url = \$(this).attr('href'); \n\t\t\t\t\t\$.post(url,function(data){ \n\t\t\t\t\t\tdata = substr(data,strpos(data,'<!--###-->')); \n\t\t\t\t\t\tdata = substr(data,0,strpos(data,'<!--/###-->')); \n\t\t\t\t\t\t\$('#ajaxContent').html(data); \n\t\t\t\t\t\tajaxPager();  \n\t\t\t\t\t\tinsertImg();\n\t\t\t\t\t\tajax_body_insert();\n\t\t\t\t\t});\n\t\t\t\t\t\n\t\t\t\t\treturn false;\n\t\t\t\t});\n\t\t\t}\n\t\t\tajaxPager();\n\t\t\tfunction insertImg(){\n\t\t\t\t\$('#insertImg').click(function(){ \n\t\t\t\t\tif(\$('#ajax_body').css('display')=='none')\n\t\t\t\t    \t\$('#ajax_body').show();\n\t\t\t\t    else\n\t\t\t\t    \t\$('#ajax_body').hide();\n\t\t\t\t });\n\t\t\t}\n\t\t\tinsertImg();\n\t\t\t");
     $this->render('index', array('pager' => $pager));
 }
Ejemplo n.º 7
0
 /**
  * 自动生成表单,使用SELECT
  * @parma  $name 字段名
  * @parma  $model 字段在Node_Field中的MODEL信息
  * @parma  $value 当前的值
  */
 function action($name, $model, $value = null)
 {
     $r = $model->relation;
     $arr = explode('.', $r);
     $table = trim($arr[0]);
     $field = trim($arr[1]);
     $rows = CDB()->from($table)->queryAll();
     $data = array();
     if ($rows) {
         foreach ($rows as $vo) {
             $data[$vo['id']] = $vo[$field];
         }
     }
     $multiple = $model->mvalue ? true : false;
     if (true === $multiple) {
         $value = $_POST['Field'][$name];
         $str = CHtml::dropDownList("NodeField[{$name}]", $value, $data, array('multiple' => $multiple));
     } else {
         $str = CHtml::dropDownList("AutoModel[{$name}]", $value, $data);
     }
     echo $str;
 }
Ejemplo n.º 8
0
<?php 
$this->endWidget();
?>
	
<?php 
/**
* 字段类型 使用AJAX
* 数据库表名及字段名
*/
$rows = CDB('SHOW TABLES')->queryAll();
foreach ($rows as $v) {
    $mysql_table = ArrHelper::first($v);
    if (in_array($mysql_table, array('node_field', 'node_content'))) {
        continue;
    }
    $row = CDB("SHOW  COLUMNS FROM  {$mysql_table}")->queryAll();
    foreach ($row as $k) {
        $f = $k['Field'];
        if (!in_array($f, array('uid', 'created', 'id', 'updated', 'language_id', 'vid', 'sort', 'display')) && strpos($f, 'id') === false) {
            $ajax_str .= "'" . $mysql_table . '.' . $f . "',";
        }
    }
}
$ajax_str = substr($ajax_str, 0, -1);
/**
* ajax 自动完成的验证规则
*/
$ruels_default = "'required:1','length: min:3 max:12'";
js_code("\n\tfunction init_type(v){ \n\t\t\$.post('" . url('node/field/ajax') . "',{id:v},function(data){ \n\t\t\t\$('#ajax').html(data);\n\t\t\tjQuery('#NodeField_relation').autocomplete({'minLength':'1','source':[" . $ajax_str . "]});\n\t\t\t\n\t\t});\n\t}\n\tinit_type(\$('#NodeField_type').val());\n\t\$('#NodeField_type').change(function(){ \n\t\tinit_type( \$(this).val() );\n\t});\n\tjQuery('#NodeField_rules').autocomplete({'minLength':'1','source':[" . $ruels_default . "]});\n");
core_js('jquery.ui');
$cssCoreUrl = Yii::app()->getClientScript()->getCoreScriptUrl();
Ejemplo n.º 9
0
 /**
 * 
 $criteria =  new CDbCriteria();
 $criteria->condition = "id = 1 or id =1";
 $node = Node::find('post',$criteria); 
 Node::find('post',1); 
 */
 static function find($table, $criteria, $pager = false, $pageSize = 10)
 {
     if (!is_object($criteria)) {
         $id = $criteria;
     }
     //所以字段key以及对应的model
     $cache = cache('node__field_table');
     $now = $cache[$table];
     $realTable = "field_" . $table;
     //设置NodeModel的表名
     NodeModel::$_table = $realTable;
     $t = new NodeModel();
     $t->refreshMetaData();
     if (is_object($criteria)) {
         if (true === $pager) {
             $count = NodeModel::model()->count($criteria);
             $pages = new CPagination($count);
             $pages->pageSize = $pageSize;
             $pages->applyLimit($criteria);
         }
         $posts = NodeModel::model()->findAll($criteria);
         if (!$posts) {
             return null;
         }
         foreach ($posts as $r) {
             $allRows[] = static::find($table, $r->id);
         }
         if (true === $pager) {
             $out = array('posts' => $allRows, 'pages' => $pages);
             return $out;
         }
         if ($criteria->limit == 1) {
             return ArrHelper::first($allRows);
         }
         return $allRows;
     }
     $fields = cache('node__content_field');
     if (!fields) {
         return null;
     }
     $rows = NodeModel::model()->findByPk($id);
     foreach ($fields[$table] as $k => $v) {
         $row[$k] = $rows->{$k};
     }
     //没有缓存是有问题的
     if (!$cache) {
         return $row;
     }
     foreach ($now as $k => $v) {
         $name = trim($v->name);
         $_relation_table = $realTable . "_" . $name;
         //真实的第三方表的内容
         $deep = $v->_relation_table;
         //是多个值的,并且是关联其他表的情况
         if ($v->relation && $v->mvalue == 1) {
             $allR = CDB()->from($_relation_table)->where('nid=:nid', array(':nid' => $id))->queryAll();
             if ($allR) {
                 foreach ($allR as $key => $al) {
                     $value = $al['value'];
                     $values = CDB()->from($deep)->where('id=:id', array(':id' => $value))->queryRow();
                     $all[$name][$value] = $values;
                 }
                 foreach ($all as $key => $value) {
                     $row[$key] = $value;
                 }
             }
         } else {
             if ($v->relation) {
                 $value = CDB()->from($deep)->where('id=:id', array(':id' => $row[$name]))->queryRow();
                 $row[$name] = $value;
             }
         }
     }
     return $row;
 }
Ejemplo n.º 10
0
 /**
  * 对字段加载HOOK,改变relation 的值
  */
 function hook()
 {
     Hook::init('model.NodeField_afterSave', function ($model) {
         CDB()->update('node_field', array('relation' => "attachments." . $model->name), 'id=:id', array(':id' => $model->id));
     });
 }
Ejemplo n.º 11
0
 /**
  * 创建关联表 
  */
 function createTableR($name, $relation = 'relation')
 {
     if (!$name) {
         return;
     }
     $name = "field_" . $name . "_" . $relation;
     $v = " varchar(255) NOT NULL";
     $t = " text NOT NULL";
     $t = " int(11) NOT NULL";
     $sql = "CREATE TABLE IF NOT EXISTS `" . $name . "` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT, \n\t\t\t  `nid` int(11) NOT NULL, \n\t\t\t  `value` int(11) NOT NULL,  \n\t\t\t  PRIMARY KEY (`id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8;\n\t\t";
     CDB($sql)->execute();
 }
Ejemplo n.º 12
0
<!DOCTYPE HTML>
	<head> 
	<meta charset="utf-8">
  	<?php 
core_js('jquery');
css(base_url() . '/misc/bootstrap/css/bootstrap.min.css');
css_code("\n \t\t\t.label-default a{color:#fff;}\n \t\t\tlabel{display:block;}\n \t\t\t.label{color:black;}\n \t\t\t#acl label{margin-right:5px;}\n \t\t\t.bs-sidenav li.active  {\n\t\t\t\tfont-weight: bold;\n\t\t\t\tcolor: #563d7c;\n\t\t\t\tbackground-color: transparent;\n\t\t\t\tborder-right: 1px solid #563d7c;\n\t\t\t}\n\t\t\t.bs-sidenav{\n\t\t\t\tbackground:#eee;\n\t\t\t\tpadding: 10px;\n \n\t\t\t\tborder:1px solid #eee;\n\t\t\t\t \n\t\t\t\t-webkit-border-radius: 6px;\n\t\t\t\t-moz-border-radius: 6px;\n\t\t\t  \n\t\t\t}\n \t\t");
js(base_url() . '/misc/bootstrap/js/bootstrap.min.js');
js(base_url() . '/misc/php.js');
widget("imagesloaded", array('tag' => 'img'));
$lang = CDB()->from('languages')->where('is_default=1')->queryRow();
$select_id = $lang['id'];
js_code("\n      if(!\$('#AutoModel_language_id').val()){\n        \$('#AutoModel_language_id option').each(function(){\n           if(\$(this).val()== " . $select_id . "){\n            \$(this).attr('selected','selected');\n           }\n\n        });\n      }\n    ");
//	widget('select2');
?>
 
 	<!--[if lt IE 9]>
	<script src="<?php 
echo base_url();
?>
/misc/html5shiv.js"></script>
	<![endif]-->
	<title><?php 
echo __('admin panel');
?>
</title>
</head> 
<body> 
<div class="navbar navbar-default navbar-static-top" role="navigation">
  <div class="container">
    <div class="navbar-header"> 
Ejemplo n.º 13
0
 protected function _config()
 {
     if (!cache('config')) {
         $rows = CDB()->from('configs')->queryAll();
         if ($rows) {
             foreach ($rows as $v) {
                 $data[$v['name']] = $v['body'];
             }
         }
         cache('config', $data);
     }
     $this->_config = cache('config');
 }
Ejemplo n.º 14
0
 function run()
 {
     $this->db = Yii::app()->db->createCommand();
     //取得文件完整路径
     $file = Yii::getPathOfAlias($this->config) . '.php';
     //取得文件配置信息
     $row = self::loadFile($file);
     $this->model = new AutoModel();
     //验证规则
     $this->model->rules = $row['_rules'];
     $_AutoModel = $row['_AutoModel'];
     //关联表的表名
     $this->relation_table = $row['_relation_table'];
     $_config = cache('config');
     if (!$_config['mlanguage']) {
         unset($row['_multiLanguage'], $row['language_id']);
     }
     //判断是不是启用了多语言
     $this->_multiLanguage = $_multiLanguage = $row['_multiLanguage'];
     $data['error'] = $row['_error'];
     unset($row['_rules'], $row['_error'], $row['_AutoModel'], $row['_multiLanguage'], $row['_relation_table']);
     $this->row = $row;
     if (!$this->table) {
         //取得数据库的名称
         $this->table = substr($this->config, strrpos($this->config, '.') + 1);
     }
     //判断是否是更新
     if (true === $this->save) {
         $id = (int) $this->id;
         if ($id) {
             $dbRow = $this->db->from($this->table)->where('id=:id', array(':id' => $id))->queryRow();
             if ($dbRow) {
                 $this->update = true;
                 $node_id = $dbRow['id'];
                 //取数据库中原来的UUID
                 $uuid = $dbRow['uuid'];
                 foreach ($row as $key => $value) {
                     $row[$key]['value'] = $dbRow[$key];
                     $this->model->{$key} = $dbRow[$key];
                 }
                 /**
                  * 取得关联表的值
                  */
                 if ($this->relation_table) {
                     // key是字段名 ,value是表名
                     foreach ($this->relation_table as $key => $value) {
                         $allR = CDB()->from($value)->where('nid=:nid', array(':nid' => $node_id))->queryAll();
                         if ($allR) {
                             foreach ($allR as $al) {
                                 $all[$key][] = $al['value'];
                             }
                             foreach ($all as $k => $v) {
                                 $_POST['Field'][$k] = $v;
                             }
                         }
                     }
                 }
             }
         }
         //设置模型对应的属性,供自动翻译多语言
         $this->model->set_attrs($row);
         $fixVid = null;
         //启用多语言判断,多语言一定是有VID的
         if (true === $_multiLanguage) {
             if ($dbRow['vid'] && $dbRow['language_id'] != trim($_POST['AutoModel']['language_id'])) {
                 $fixVid = $dbRow['vid'];
             }
             $vid = $dbRow['vid'];
             /**
              * 已经存在的多语言记录
              */
             $all = Yii::app()->db->createCommand()->from($this->table)->where("vid=:vid", array(':vid' => $dbRow['vid']))->queryAll();
             foreach ($all as $al) {
                 $muitLang[$al['language_id']] = $al['id'];
             }
         }
         if (isset($_POST['AutoModel'])) {
             //关联到其他表的值
             $NodeField = $_POST['NodeField'];
             if ($NodeField) {
                 foreach ($NodeField as $key => $value) {
                     //关联表名
                     $rale = $this->relation_table[$key];
                     //用来保存到数据库的
                     $relation_datas[$rale] = $value;
                 }
             }
             //对AutoModel属性赋值
             foreach ($row as $key => $value) {
                 $postV = $_POST['AutoModel'][$key];
                 //判断是否是多值
                 if ($NodeField[$key]['mvalue'] != 1 && is_array($postV)) {
                     $postV = ArrHelper::first($postV);
                 } elseif (is_array($postV)) {
                     $postV = serialize($postV);
                 }
                 //当字段配置中 insert 值为false时不写入主表
                 if ($value['insert'] === false) {
                     continue;
                 }
                 $this->model->{$key} = trim($postV);
                 $saveDatas[$key] = trim($postV);
             }
             //验证规则
             if ($this->model->validate()) {
                 $column = cache('DBColumns_' . $this->table);
                 if (!$column) {
                     $columns = Yii::app()->db->createCommand("SHOW  COLUMNS FROM  `" . $this->table . "`")->queryAll();
                     foreach ($columns as $c) {
                         $column[$c['Field']] = $c['Field'];
                     }
                 }
                 /**
                  * 自动加载 application.components.AutoModel 下的文件
                  */
                 $insertDatas = array();
                 $updateDatas = array();
                 if ($_AutoModel) {
                     foreach ($_AutoModel as $AutoModel) {
                         $AutoModel = $AutoModel . 'AutoModel';
                         Yii::import("application.components.AutoModel.{$AutoModel}");
                         $objModel = new $AutoModel();
                         if (method_exists($AutoModel, 'insert')) {
                             $insertDatas += $objModel->insert($saveDatas);
                         }
                         if (method_exists($AutoModel, 'update')) {
                             $updateDatas += $objModel->update($saveDatas);
                         }
                         if (method_exists($AutoModel, 'after')) {
                             $after[] = $objModel;
                         }
                         /**
                          * 判断字段是否存在
                          */
                         if (is_array($objModel->fields)) {
                             foreach ($objModel->fields as $v) {
                                 if (!$column[$v]) {
                                     unset($insertDatas[$v], $updateDatas[$v]);
                                 }
                             }
                         } else {
                             $v = $objModel->fields;
                             if (!$column[$v]) {
                                 unset($insertDatas[$v], $updateDatas[$v]);
                             }
                         }
                     }
                 }
                 //如果不是更新,将取AUTOMODEL里面的UUID值
                 if (!$uuid) {
                     $uuid = $insertDatas['uuid'];
                 }
                 if (true === $this->update) {
                     /**
                      * 判断更新需要操作的字段
                      */
                     if ($fixVid) {
                         $updateDatas['vid'] = $fixVid;
                     }
                     if ($updateDatas) {
                         foreach ($updateDatas as $_k => $_v) {
                             $saveDatas[$_k] = $_v;
                         }
                     }
                     if ($fixVid) {
                         if (!$this->db->from($this->table)->where('vid=' . $fixVid . ' and language_id=' . $saveDatas['language_id'])->queryRow()) {
                             $this->db->insert($this->table, $saveDatas);
                         } else {
                             unset($saveDatas['vid']);
                             $this->db->update($this->table, $saveDatas, 'id=:id', array(':id' => $id));
                         }
                     } else {
                         unset($saveDatas['vid']);
                         $this->db->update($this->table, $saveDatas, 'id=:id', array(':id' => $id));
                     }
                 } else {
                     /**
                      * 判断写入需要操作的字段
                      */
                     if ($insertDatas) {
                         foreach ($insertDatas as $_k => $_v) {
                             $saveDatas[$_k] = $_v;
                         }
                     }
                     $this->db->insert($this->table, $saveDatas);
                 }
                 //写入主表完成,写入关联表
                 if ($relation_datas) {
                     /**
                      * 当没有node_id 时,也就是新建操作时,将查寻一次数据库取得node_id的值
                      */
                     if (!$node_id) {
                         $row = $this->db->from($this->table)->where('uuid=:uuid', array(':uuid' => $uuid))->queryRow();
                         $node_id = $dbRow['id'];
                     }
                     foreach ($relation_datas as $RT => $volist) {
                         CDB()->delete($RT, 'nid=:nid', array(':nid' => $node_id));
                         foreach ($volist as $vo) {
                             CDB()->insert($RT, array('nid' => $node_id, 'value' => $vo));
                         }
                     }
                 }
                 //所以操作后
                 if ($after) {
                     foreach ($after as $af) {
                         $af->after($this->db, $this->table, $data, $id);
                     }
                 }
                 if (true === $_multiLanguage) {
                     cache('language_' . $this->table . $vid, false);
                 }
                 flash('success', __('success'));
                 $this->controller->refresh();
             }
         }
         if (!$this->editUrl) {
             $this->editUrl = $this->controller->module->id . '/' . $this->controller->id . '/update';
         }
         if (!$this->createUrl) {
             $this->createUrl = $this->controller->module->id . '/' . $this->controller->id . '/create';
         }
         $data['model'] = $this->model;
         $data['row'] = $row;
         $data['multiLanguage'] = $this->_multiLanguage;
         $data['muitLang'] = $muitLang;
         $data['createUrl'] = $this->createUrl;
         $data['editUrl'] = $this->editUrl;
         $this->render('BuilderView', $data);
     }
 }
Ejemplo n.º 15
0
                        <span><img src="<?php 
echo theme_url();
?>
/images/13.jpg" /></span>
                        <span><img src="<?php 
echo theme_url();
?>
/images/14.jpg" /></span>
                    </p>
                </div>
            </div>
        </div>
        <div class="mainnav">
        	<ul class="nav">
    			<?php 
$menus = CDB()->from('menus')->where('is_admin=0')->order("sort desc,id desc")->queryAll();
foreach ($menus as $v) {
    ?>
            	<li class="<?php 
    if (Helper::activeMenu($v['url'])) {
        ?>
se<?php 
    }
    ?>
">
            		<a href="<?php 
    echo url($v['url']);
    ?>
"><?php 
    echo __($v['name']);
    ?>