module.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. class MusicModule extends WeModule {
  8. public $tablename = 'music_reply';
  9. public function fieldsFormDisplay($rid = 0) {
  10. global $_W;
  11. load()->func('tpl');
  12. if (!empty($rid)) {
  13. $replies = pdo_fetchall("SELECT * FROM ".tablename($this->tablename)." WHERE rid = :rid ORDER BY `id` ASC", array(':rid' => $rid));
  14. $replies = istripslashes($replies);
  15. }
  16. include $this->template('form');
  17. }
  18. public function fieldsFormValidate($rid = 0) {
  19. global $_GPC;
  20. if(empty($_GPC['title'])) {
  21. return '必须填写有效的回复内容.';
  22. }
  23. foreach($_GPC['title'] as $k => $v) {
  24. $row = array();
  25. $row['title'] = $v;
  26. $row['url'] = $_GPC['url'][$k];
  27. $row['hqurl'] = $_GPC['hqurl'][$k];
  28. $row['description'] = $_GPC['description'][$k];
  29. $this->replies[] = $row;
  30. }
  31. if(empty($this->replies)) {
  32. return '必须填写有效的回复内容.';
  33. }
  34. foreach($this->replies as &$r) {
  35. if(trim($r['title']) == '' || (trim($r['url']) == '' && trim($r['hqurl']) == '')) {
  36. return '必须填写有效的回复内容.';
  37. }
  38. $r['description'] = htmlspecialchars_decode($r['description']);
  39. }
  40. return '';
  41. }
  42. public function fieldsFormSubmit($rid = 0) {
  43. global $_GPC, $_W;
  44. $sql = 'DELETE FROM '. tablename($this->tablename) . ' WHERE `rid`=:rid';
  45. $pars = array();
  46. $pars[':rid'] = $rid;
  47. pdo_query($sql, $pars);
  48. foreach($this->replies as $reply) {
  49. $reply['rid'] = $rid;
  50. pdo_insert($this->tablename, $reply);
  51. }
  52. return true;
  53. }
  54. public function ruleDeleted($rid = 0) {
  55. global $_W;
  56. $replies = pdo_fetchall("SELECT id, url FROM ".tablename($this->tablename)." WHERE rid = '$rid'");
  57. $deleteid = array();
  58. if (!empty($replies)) {
  59. foreach ($replies as $index => $row) {
  60. $deleteid[] = $row['id'];
  61. }
  62. }
  63. pdo_delete($this->tablename, "id IN ('".implode("','", $deleteid)."')");
  64. return true;
  65. }
  66. public function doFormDisplay() {
  67. global $_W, $_GPC;
  68. $result = array('error' => 0, 'message' => '', 'content' => '');
  69. $result['content']['id'] = $GLOBALS['id'] = 'add-row-news-'.$_W['timestamp'];
  70. $result['content']['html'] = $this->template('item', TEMPLATE_FETCH);
  71. exit(json_encode($result));
  72. }
  73. public function doUploadMusic() {
  74. global $_W;
  75. checklogin();
  76. if (empty($_FILES['attachFile']['name'])) {
  77. $result['message'] = '请选择要上传的音乐!';
  78. exit(json_encode($result));
  79. }
  80. if ($_FILES['attachFile']['error'] != 0) {
  81. $result['message'] = '上传失败,请重试!';
  82. exit(json_encode($result));
  83. }
  84. if ($file = $this->fileUpload($_FILES['attachFile'], 'music')) {
  85. if (!$file['success']) {
  86. exit(json_encode($file));
  87. }
  88. $result['url'] = $_W['config']['upload']['attachdir'] . $file['path'];
  89. $result['error'] = 0;
  90. $result['filename'] = $file['path'];
  91. exit(json_encode($result));
  92. }
  93. }
  94. public function doDelete() {
  95. global $_W,$_GPC;
  96. $id = intval($_GPC['id']);
  97. $sql = "SELECT id, rid, url, hqurl FROM " . tablename($this->tablename) . " WHERE `id`=:id";
  98. $row = pdo_fetch($sql, array(':id'=>$id));
  99. if (empty($row)) {
  100. itoast('抱歉,回复不存在或是已经被删除!', '', 'error');
  101. }
  102. if (pdo_delete($this->tablename, array('id' => $id))) {
  103. itoast('删除回复成功', '', 'success');
  104. }
  105. }
  106. private function fileUpload($file, $type) {
  107. global $_W;
  108. set_time_limit(0);
  109. $_W['uploadsetting'] = array();
  110. $_W['uploadsetting']['music']['folder'] = 'music';
  111. $_W['uploadsetting']['music']['extentions'] = array('mp3', 'wma', 'wav', 'amr');
  112. $_W['uploadsetting']['music']['limit'] = 50000;
  113. $result = array();
  114. $upload = file_upload($file, 'music');
  115. if (is_error($upload)) {
  116. iajax(1, $upload['message']);
  117. }
  118. $result['url'] = $upload['url'];
  119. $result['error'] = 0;
  120. $result['filename'] = $upload['path'];
  121. return $result;
  122. }
  123. }