人人商城

module.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. $reply = array(
  49. 'rid' => $rid,
  50. 'description' => $_GPC['description'],
  51. 'apiurl' => empty($_GPC['type']) ? $_GPC['apilocal'] : $_GPC['apiurl'],
  52. 'token' => $_GPC['wetoken'],
  53. 'default_text' => $_GPC['default-text'],
  54. 'cachetime' => intval($_GPC['cachetime']),
  55. );
  56. $is_exists = pdo_fetchcolumn('SELECT id FROM ' . tablename($this->tablename) . ' WHERE rid = :rid', array(':rid' => $rid));
  57. if(!empty($is_exists)) {
  58. if(pdo_update($this->tablename, $reply, array('rid' => $rid)) !== false) {
  59. return true;
  60. }
  61. } else {
  62. if(pdo_insert($this->tablename, $reply)) {
  63. return true;
  64. }
  65. }
  66. return false;
  67. }
  68. public function ruleDeleted($rid = 0) {
  69. pdo_delete($this->tablename, array('rid' => $rid));
  70. }
  71. public function doSwitch() {
  72. global $_W, $_GPC;
  73. $m = array_merge($_W['modules']['userapi'], $_W['account']['modules']['userapi']);
  74. $cfg = $m['config'];
  75. if($_W['ispost']) {
  76. $rids = explode(',', $_GPC['rids']);
  77. if(is_array($rids)) {
  78. $cfg = array();
  79. foreach($rids as $rid) {
  80. $cfg[intval($rid)] = true;
  81. }
  82. $this->saveSettings($cfg);
  83. }
  84. exit();
  85. }
  86. load()->model('reply');
  87. $rs = reply_search("uniacid = 0 AND module = 'userapi' AND `status`=1");
  88. $ds = array();
  89. foreach($rs as $row) {
  90. $reply = pdo_fetch('SELECT * FROM ' . tablename($this->tablename) . ' WHERE `rid`=:rid', array(':rid' => $row['id']));
  91. $r = array();
  92. $r['title'] = $row['name'];
  93. $r['rid'] = $row['id'];
  94. $r['description'] = $reply['description'];
  95. $r['switch'] = $cfg[$r['rid']] ? ' checked="checked"' : '';
  96. $ds[] = $r;
  97. }
  98. include $this->template('switch');
  99. }
  100. }