PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Tpblog/Blog/Lib/Action/PublicAction.class.php

http://tpblog.googlecode.com/
PHP | 228 lines | 155 code | 18 blank | 55 comment | 20 complexity | 2e6c7604e9c7a78aa1756ba4be16281b MD5 | raw file
  1. <?php
  2. class PublicAction extends Action
  3. {
  4. ##?????
  5. public function getAttach()
  6. {
  7. ##??????
  8. $id = $_GET['id'];
  9. $dao = D("Attachment");
  10. $attachs = $dao->findAll("module='".MODULE_NAME."' and blogid='$id'");
  11. ##??????
  12. $this->assign("attachs",$attachs);
  13. }
  14. ##???????
  15. public function _trigger($vo)
  16. {
  17. if(ACTION_NAME=='insert')
  18. {
  19. ##???????
  20. $dao = D("Attachment");
  21. $attach['verify'] = 0;
  22. $attach['blogid'] = $vo->id;
  23. $dao->save($attach,"verify='".$_SESSION['attach_verify']."'");
  24. }
  25. $this->saveTag($vo->tags,$vo->id);
  26. }
  27. /**
  28. +----------------------------------------------------------
  29. * ????????
  30. *
  31. * ??????????????????
  32. * ????????parent::insert??
  33. +----------------------------------------------------------
  34. * @access public
  35. +----------------------------------------------------------
  36. * @return void
  37. +----------------------------------------------------------
  38. * @throws ThinkExecption
  39. +----------------------------------------------------------
  40. */
  41. public function insert()
  42. {
  43. ##????????????????????
  44. if(method_exists($this,'_operation')) {
  45. $this->_operation();
  46. }
  47. ##????????
  48. $model = $this->getModelClass();
  49. if(!empty($model)) {
  50. $this->_insert($model);
  51. }
  52. }
  53. /**
  54. +----------------------------------------------------------
  55. * ????????
  56. * ?????edit???????????
  57. +----------------------------------------------------------
  58. * @access public
  59. +----------------------------------------------------------
  60. * @return string
  61. +----------------------------------------------------------
  62. * @throws ThinkExecption
  63. +----------------------------------------------------------
  64. */
  65. public function read()
  66. {
  67. $this->edit();
  68. return;
  69. }
  70. /**
  71. +----------------------------------------------------------
  72. * ?????
  73. +----------------------------------------------------------
  74. * @access public
  75. +----------------------------------------------------------
  76. * @return void
  77. +----------------------------------------------------------
  78. * @throws ThinkExecption
  79. +----------------------------------------------------------
  80. */
  81. public function verify()
  82. {
  83. $type = isset($_GET['type'])?$_GET['type']:'gif';
  84. import("ORG.Util.Image");
  85. Image::buildImageVerify(4,1,$type);
  86. }
  87. public function delete($model='')
  88. {
  89. ##??????
  90. if(empty($model)) {
  91. $model = $this->getModelClass();
  92. }
  93. if(!empty($model)) {
  94. $id = $_REQUEST[$model->getPk()];
  95. if(isset($id)) {
  96. $condition[$model->getPk()] = $id;
  97. if($model->delete($condition)){
  98. if($this->get('ajax')) {
  99. $this->ajaxReturn($id,L('_DELETE_SUCCESS_'),1);
  100. }else{
  101. $this->success(L('_DELETE_SUCCESS_'));
  102. }
  103. }else {
  104. $this->error(L('_DELETE_FAIL_'));
  105. }
  106. }else {
  107. $this->error(L('_ERROR_ACTION_'));
  108. }
  109. }
  110. }
  111. ##????
  112. public function comment()
  113. {
  114. ##??????
  115. $comm = D("Comment");
  116. $vo = $comm->create();
  117. if(!$vo) {
  118. $this->error($comm->getError());
  119. }
  120. ##????
  121. $result = $comm->add();
  122. if($result) {
  123. ##?????
  124. $this->succusss("????");
  125. $objDao = D("Blog");
  126. $objDao->setInc('comnum',"gid='".$vo->gid."'");
  127. $this->redirect($vo->gid,"Blog");
  128. }else {
  129. $this->error($vo,$dao->getError().'?????',0);
  130. }
  131. }
  132. public function saveTag($tags,$id,$module=MODULE_NAME)
  133. {
  134. if(!empty($tags) && !empty($id)) {
  135. $dao = D("Tag");
  136. $taggedDao = D("Tagged");
  137. ##?????????
  138. $exists_tags = $taggedDao->getFields("id,tagId","module='{$module}' and recordId='{$id}'");
  139. $taggedDao->deleteAll("module='{$module}' and recordId='{$id}'");
  140. $tags = explode(' ',$tags);
  141. foreach($tags as $key=>$val) {
  142. $val = trim($val);
  143. if(!empty($val)) {
  144. $tag = $dao->find("module='{$module}' and name='$val'");
  145. if($tag) {
  146. ##??????
  147. if(!in_array($tag->id,$exists_tags)) {
  148. $dao->setInc('count','id='.$tag->id);
  149. }
  150. }else {
  151. ##??????
  152. $tag = new stdClass();
  153. $tag->name = $val;
  154. $tag->count = 1;
  155. $tag->module = $module;
  156. $result = $dao->add($tag);
  157. $tag->id = $result;
  158. }
  159. ##??tag????
  160. $t = new stdClass();
  161. $t->module = $module;
  162. $t->recordId = $id;
  163. $t->tagTime = time();
  164. $t->tagId = $tag->id;
  165. $taggedDao->add($t);
  166. }
  167. }
  168. }
  169. }
  170. public function download()
  171. {
  172. import("ORG.Net.Http");
  173. $id = $_GET['id'];
  174. $dao = D("Attachment");
  175. $attach = $dao->getByAid($id);
  176. $filename = $attach->filepath.$attach->savename;
  177. if(is_file($filename)) {
  178. if(!isset($_SESSION['attach_down_count_'.$id])) {
  179. ## ????
  180. $dao->setInc('downcount',"aid=".$id);
  181. $_SESSION['attach_down_count_'.$id] = true;
  182. }
  183. Http::download($filename,auto_charset($attach->name,'utf-8','gbk'));
  184. }
  185. }
  186. ##????
  187. public function search()
  188. {
  189. if(empty($_POST['title']))
  190. {
  191. $this->error('????????????');
  192. }else{
  193. $blog = D("Blog");
  194. if($_POST['title'])
  195. {
  196. $map['title'] = array('like','%'.$_POST['title'].'%'); //?????????????(like %)
  197. $list = $blog->where($map)->order('gid desc')->limit('0,5')->findAll();
  198. }
  199. if(!$list)
  200. {
  201. $this->error('???????????');
  202. }else{
  203. $this->assign('mode','normal');
  204. $this->assign('list',$list);
  205. $this->display("index");
  206. }
  207. }
  208. }
  209. }//?????
  210. ?>