/trunk/Tpblog/Blog/Lib/Action/PublicAction.class.php
PHP | 228 lines | 155 code | 18 blank | 55 comment | 20 complexity | 2e6c7604e9c7a78aa1756ba4be16281b MD5 | raw file
- <?php
- class PublicAction extends Action
- {
- ##?????
- public function getAttach()
- {
- ##??????
- $id = $_GET['id'];
- $dao = D("Attachment");
- $attachs = $dao->findAll("module='".MODULE_NAME."' and blogid='$id'");
- ##??????
- $this->assign("attachs",$attachs);
- }
- ##???????
- public function _trigger($vo)
- {
- if(ACTION_NAME=='insert')
- {
- ##???????
- $dao = D("Attachment");
- $attach['verify'] = 0;
- $attach['blogid'] = $vo->id;
- $dao->save($attach,"verify='".$_SESSION['attach_verify']."'");
- }
- $this->saveTag($vo->tags,$vo->id);
- }
- /**
- +----------------------------------------------------------
- * ????????
- *
- * ??????????????????
- * ????????parent::insert??
- +----------------------------------------------------------
- * @access public
- +----------------------------------------------------------
- * @return void
- +----------------------------------------------------------
- * @throws ThinkExecption
- +----------------------------------------------------------
- */
- public function insert()
- {
- ##????????????????????
- if(method_exists($this,'_operation')) {
- $this->_operation();
- }
-
- ##????????
- $model = $this->getModelClass();
- if(!empty($model)) {
- $this->_insert($model);
- }
- }
-
- /**
- +----------------------------------------------------------
- * ????????
- * ?????edit???????????
- +----------------------------------------------------------
- * @access public
- +----------------------------------------------------------
- * @return string
- +----------------------------------------------------------
- * @throws ThinkExecption
- +----------------------------------------------------------
- */
- public function read()
- {
- $this->edit();
- return;
- }
-
-
-
-
-
-
-
-
- /**
- +----------------------------------------------------------
- * ?????
- +----------------------------------------------------------
- * @access public
- +----------------------------------------------------------
- * @return void
- +----------------------------------------------------------
- * @throws ThinkExecption
- +----------------------------------------------------------
- */
- public function verify()
- {
- $type = isset($_GET['type'])?$_GET['type']:'gif';
- import("ORG.Util.Image");
- Image::buildImageVerify(4,1,$type);
- }
-
- public function delete($model='')
- {
- ##??????
- if(empty($model)) {
- $model = $this->getModelClass();
- }
- if(!empty($model)) {
- $id = $_REQUEST[$model->getPk()];
- if(isset($id)) {
- $condition[$model->getPk()] = $id;
- if($model->delete($condition)){
- if($this->get('ajax')) {
- $this->ajaxReturn($id,L('_DELETE_SUCCESS_'),1);
- }else{
- $this->success(L('_DELETE_SUCCESS_'));
- }
- }else {
- $this->error(L('_DELETE_FAIL_'));
- }
- }else {
- $this->error(L('_ERROR_ACTION_'));
- }
- }
- }
-
- ##????
- public function comment()
- {
- ##??????
- $comm = D("Comment");
- $vo = $comm->create();
- if(!$vo) {
- $this->error($comm->getError());
- }
- ##????
- $result = $comm->add();
- if($result) {
- ##?????
- $this->succusss("????");
- $objDao = D("Blog");
- $objDao->setInc('comnum',"gid='".$vo->gid."'");
- $this->redirect($vo->gid,"Blog");
- }else {
- $this->error($vo,$dao->getError().'?????',0);
- }
- }
-
- public function saveTag($tags,$id,$module=MODULE_NAME)
- {
- if(!empty($tags) && !empty($id)) {
- $dao = D("Tag");
- $taggedDao = D("Tagged");
- ##?????????
- $exists_tags = $taggedDao->getFields("id,tagId","module='{$module}' and recordId='{$id}'");
- $taggedDao->deleteAll("module='{$module}' and recordId='{$id}'");
- $tags = explode(' ',$tags);
- foreach($tags as $key=>$val) {
- $val = trim($val);
- if(!empty($val)) {
- $tag = $dao->find("module='{$module}' and name='$val'");
- if($tag) {
- ##??????
- if(!in_array($tag->id,$exists_tags)) {
- $dao->setInc('count','id='.$tag->id);
- }
-
- }else {
- ##??????
- $tag = new stdClass();
- $tag->name = $val;
- $tag->count = 1;
- $tag->module = $module;
- $result = $dao->add($tag);
- $tag->id = $result;
- }
- ##??tag????
- $t = new stdClass();
- $t->module = $module;
- $t->recordId = $id;
- $t->tagTime = time();
- $t->tagId = $tag->id;
- $taggedDao->add($t);
- }
- }
- }
- }
-
-
- public function download()
- {
- import("ORG.Net.Http");
- $id = $_GET['id'];
- $dao = D("Attachment");
- $attach = $dao->getByAid($id);
- $filename = $attach->filepath.$attach->savename;
- if(is_file($filename)) {
- if(!isset($_SESSION['attach_down_count_'.$id])) {
- ## ????
- $dao->setInc('downcount',"aid=".$id);
- $_SESSION['attach_down_count_'.$id] = true;
- }
- Http::download($filename,auto_charset($attach->name,'utf-8','gbk'));
- }
- }
-
- ##????
- public function search()
- {
- if(empty($_POST['title']))
- {
- $this->error('????????????');
- }else{
- $blog = D("Blog");
- if($_POST['title'])
- {
- $map['title'] = array('like','%'.$_POST['title'].'%'); //?????????????(like %)
- $list = $blog->where($map)->order('gid desc')->limit('0,5')->findAll();
- }
- if(!$list)
- {
- $this->error('???????????');
- }else{
- $this->assign('mode','normal');
- $this->assign('list',$list);
- $this->display("index");
- }
- }
- }
-
- }//?????
- ?>