module.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 UserapiModule extends WeModule {
  8. public $tablename = 'userapi_reply';
  9. public function fieldsFormDisplay($rid = 0) {
  10. global $_W;
  11. if (!empty($rid)) {
  12. $row = pdo_fetch("SELECT * FROM ".tablename($this->tablename)." WHERE rid = :rid ORDER BY `id` DESC", array(':rid' => $rid));
  13. $row['type'] = 1; if (!strexists($row['apiurl'], 'http://') && !strexists($row['apiurl'], 'https://')) {
  14. $row['apilocal'] = $row['apiurl'];
  15. $row['type'] = 0; $row['apiurl'] = '';
  16. }
  17. } else {
  18. $row = array(
  19. 'cachetime' => 0,
  20. 'type' => 1
  21. );
  22. }
  23. $path = IA_ROOT . '/framework/builtin/userapi/api/';
  24. if (is_dir($path)) {
  25. $apis = array();
  26. if ($handle = opendir($path)) {
  27. while (false !== ($file = readdir($handle))) {
  28. if ($file != "." && $file != "..") {
  29. $apis[] = $file;
  30. }
  31. }
  32. }
  33. }
  34. include $this->template('form');
  35. }
  36. public function fieldsFormValidate($rid = 0) {
  37. global $_GPC;
  38. if (($_GPC['type'] && empty($_GPC['apiurl'])) || (empty($_GPC['type']) && empty($_GPC['apilocal']))) {
  39. itoast('请填写接口地址!', '', '');
  40. }
  41. if ($_GPC['type'] && empty($_GPC['token'])) {
  42. itoast('请填写Token值!', '', '');
  43. }
  44. return '';
  45. }
  46. public function fieldsFormSubmit($rid = 0) {
  47. global $_GPC, $_W;
  48. permission_check_account_user('platform_reply_userapi');
  49. $rid = intval($rid);
  50. $reply = array(
  51. 'rid' => $rid,
  52. 'description' => safe_gpc_string($_GPC['description']),
  53. 'apiurl' => empty($_GPC['type']) ? safe_gpc_string($_GPC['apilocal']) : safe_gpc_string($_GPC['apiurl']),
  54. 'token' => safe_gpc_string($_GPC['wetoken']),
  55. 'default_text' => safe_gpc_string($_GPC['default-text']),
  56. 'cachetime' => intval($_GPC['cachetime']),
  57. );
  58. $rule_exists = pdo_get('rule', array('id' => $rid, 'uniacid' => $_W['uniacid']));
  59. if (empty($rule_exists)) {
  60. return false;
  61. }
  62. $is_exists = pdo_fetchcolumn('SELECT id FROM ' . tablename($this->tablename) . ' WHERE rid = :rid', array(':rid' => $rid));
  63. if(!empty($is_exists)) {
  64. if(pdo_update($this->tablename, $reply, array('rid' => $rid)) !== false) {
  65. return true;
  66. }
  67. } else {
  68. if(pdo_insert($this->tablename, $reply)) {
  69. return true;
  70. }
  71. }
  72. return false;
  73. }
  74. public function ruleDeleted($rid = 0) {
  75. global $_W;
  76. $rid = intval($rid);
  77. permission_check_account_user('platform_reply_userapi');
  78. $rule_exists = pdo_get('rule', array('id' => $rid, 'uniacid' => $_W['uniacid']));
  79. if (empty($rule_exists)) {
  80. return false;
  81. }
  82. $result = pdo_delete($this->tablename, array('rid' => $rid));
  83. return $result;
  84. }
  85. public function doSwitch() {
  86. global $_W, $_GPC;
  87. $m = array_merge($_W['modules']['userapi'], $_W['account']['modules']['userapi']);
  88. $cfg = $m['config'];
  89. if($_W['ispost']) {
  90. $rids = explode(',', $_GPC['rids']);
  91. if(is_array($rids)) {
  92. $cfg = array();
  93. foreach($rids as $rid) {
  94. $cfg[intval($rid)] = true;
  95. }
  96. $this->saveSettings($cfg);
  97. }
  98. exit();
  99. }
  100. load()->model('reply');
  101. $rs = reply_search("uniacid = 0 AND module = 'userapi' AND `status`=1");
  102. $ds = array();
  103. foreach($rs as $row) {
  104. $reply = pdo_fetch('SELECT * FROM ' . tablename($this->tablename) . ' WHERE `rid`=:rid', array(':rid' => $row['id']));
  105. $r = array();
  106. $r['title'] = $row['name'];
  107. $r['rid'] = $row['id'];
  108. $r['description'] = $reply['description'];
  109. $r['switch'] = $cfg[$r['rid']] ? ' checked="checked"' : '';
  110. $ds[] = $r;
  111. }
  112. include $this->template('switch');
  113. }
  114. }