昨日用ECMall完成了后台模块的开发,模块开发与smarty开发类似,html实现前台,后台php控制输出。
今日写ECMall前台实现,首先要将网站前台头部代码调用出来,此问题仍在考虑中。 。。最终只能将网站头尾copy过来,放在模块里调用。
ECMall插件开发,将后台写好的模块做成插件的形式在首页底部添加
function add()
{
if (!IS_POST)
{
$cate_id = isset($_GET['cate_id']) ? intval($_GET['cate_id']) : 0;
if (empty($cate_id))
{
$this->show_warning('no_such_data');
return;
}
$this->assign('cate_id', $cate_id);
$this->import_resource(array('script' => 'jquery.plugins/jquery.validate.js,change_upload.js'));
//$template_name = $this->_get_template_name();
//$style_name = $this->_get_style_name();
$this->assign('build_editor', $this->_build_editor(array(
'name' => 'content',
'content_css' => SITE_URL . "/themes/mall/{$template_name}/styles/{$style_name}/css/ecmall.css"
)));
$this->assign('build_upload', $this->_build_upload(array('belong' => BELONG_ARTICLE, 'item_id' => $article_id))); // 构建swfupload上传组件
$this->display('articleedit.form.html');
}
else
{
//提交新内容
$data = array();
$data['title'] = $_POST['title'];
if (!empty($_POST['cate_id']))
{
$data['cate_id'] = $_POST['cate_id'];
}
$data['content'] = $_POST['content'];
$rows=$this->myfooter_mod->add($data);
if ($this->myfooter_mod->has_error())
{
$this->show_warning($this->myfooter_mod->get_error());
return;
}
$this->show_message('add_article_successed',
'back_list', 'index.php?module=myfooter&act=listarticle&cate_id='.$_POST['cate_id'],
'edit_again', 'index.php?module=myfooter&act=edit&article_id=' . $rows);
}
}
//文章列表页显示
function listarticle()
{
/* 处理cate_id */
$cate_id = !empty($_GET['cate_id'])? intval($_GET['cate_id']) : $this->_ACC[ACC_NOTICE];
//echo $cate_id;
/* 分类下的所有文章 */
$all = $this->_get_article($cate_id);
$articles = $all['articles'];
$page = $all['page'];
$this->assign('articles', $articles);
$this->assign('cate_id', $cate_id);
$this->assign('page_info', $page);
$this->display('articlelist.index.html');
}
function _get_article($cate_id)
{
$sort_order = 'add_time DESC';
$page = $this->_get_page(10); //获取分页信息
$articles = $this->myfooter_mod->find(array(
'conditions' => 'cate_id='.$cate_id,
'limit' => $page['limit'],
'order' => $sort_order,
'count' => true,
)); //找出所有符合条件的文章
$page['item_count']=$this->myfooter_mod->getCount();
$this->_format_page($page);
return array('page'=>$page, 'articles'=>$articles);
}
//文章内容页编辑方法
function edit()
{
$article_id = isset($_GET['article_id']) ? intval($_GET['article_id']) : 0;
if (empty($article_id))
{
$this->show_warning('no_such_data');
return;
}
if (!IS_POST)
{
//加载页面时装载原有文章内容
//$data_article = $this->myfooter_mod->find('article_id='.$article_id);
//$article = $data_article[1];
//print_r($article);
/* 当前文章的附件 */
$files_belong_article = $this->_uploadedfile_mod->find(array(
'conditions' => 'store_id = 0 AND item_id=' . $article_id,
'fields' => 'this.file_id, this.file_name, this.file_path',
'order' => 'add_time DESC'
));
$find_data = $this->myfooter_mod->find($article_id);
if (empty($find_data))
{
$this->show_warning('no_such_article');
return;
}
$article = current($find_data);
$this->assign("id", $article_id);
$this->import_resource(array('script' => 'jquery.plugins/jquery.validate.js,change_upload.js'));
$this->assign('cate_id', $article[cate_id]);
$this->assign('article', $article);
//$template_name = $this->_get_template_name();
//$style_name = $this->_get_style_name();
$this->assign('build_editor', $this->_build_editor(array(
'name' => 'content',
'content_css' => SITE_URL . "/themes/mall/{$template_name}/styles/{$style_name}/css/ecmall.css"
)));
$this->assign('build_upload', $this->_build_upload(array('belong' => BELONG_ARTICLE, 'item_id' => $article_id))); // 构建swfupload上传组件
$this->display('articleedit.form.html');
}
else
{
//提交新内容
$data = array();
$data['title'] = $_POST['title'];
$data['cate_id'] = $_POST['cate_id'];
$data['link'] = $_POST['link'];
$data['if_show'] = $_POST['if_show'];
$data['sort_order'] = $_POST['sort_order'];
$data['content'] = $_POST['content'];
$rows=$this->myfooter_mod->edit($article_id, $data);
if ($this->myfooter_mod->has_error())
{
$this->show_warning($this->myfooter_mod->get_error());
return;
}
$this->show_message('edit_article_successed',
'back_list', 'index.php?module=myfooter&act=listarticle&cate_id='.$_POST['cate_id'],
'edit_again', 'index.php?module=myfooter&act=edit&article_id=' . $article_id.'&cate_id='.$cate_id);
}
}
function drop()
{
//print_r($_POST['checkids']);
$article_ids = $this->filter_ids($_GET['id']);
if (!$article_ids)
{
$this->show_warning('no_such_data');
return;
}
foreach ($article_ids as $article_id){
if (file_exists(ROOT_PATH . '/temp/js/datacallcache'. $article_id . '.js'))
{
@unlink(ROOT_PATH . '/temp/js/datacallcache'. $article_id . '.js');
}
$this->myfooter_mod->drop($article_id);
}
$this->show_message('drop_data_successed');
}
function filter_ids($ids)
{
$ids = isset($ids) ? trim($ids) : '';
if (!$ids)
{
return ;
}
$ids=explode(',',$ids);
foreach ($ids as $key => $id){
$ids[$key] = isset($id) ? intval($id) : 0;
}
$ids = array_unique($ids);
//$data_call = $this->myfooter_mod->getAll();
foreach ($ids as $value)
{
$filter_ids[] = $value;
}
if ($filter_ids == null)
{
return ;
}
return $filter_ids;
}
function drop_uploadedfile(){
$file_id = isset($_GET['file_id']) ? intval($_GET['file_id']) : 0;
if ($file_id && $this->_uploadedfile_mod->drop($file_id))
{
$this->json_result('drop_ok');
return;
}
else
{
$this->json_error('drop_error');
return;
}
}