site.mod.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. function site_cover($coverparams = array()) {
  8. $coverreply_table = table('core_cover_reply');
  9. if (!empty($coverparams['multiid'])) {
  10. $coverreply_table->searchWithMultiid(intval($coverparams['multiid']));
  11. }
  12. $cover = $coverreply_table->getByModuleAndUniacid($coverparams['module'], $coverparams['uniacid']);
  13. if (empty($cover['rid'])) {
  14. $rule = array(
  15. 'uniacid' => intval($coverparams['uniacid']),
  16. 'name' => safe_gpc_string($coverparams['title']),
  17. 'module' => 'cover',
  18. 'status' => 1,
  19. );
  20. table('rule')->fill($rule)->save();
  21. $rid = pdo_insertid();
  22. } else {
  23. $rule = array(
  24. 'name' => $coverparams['title'],
  25. );
  26. table('rule')->fill($rule)->whereId($cover['rid'])->save();
  27. $rid = $cover['rid'];
  28. }
  29. if (!empty($rid)) {
  30. pdo_delete('rule_keyword', array('rid' => $rid, 'uniacid' => $coverparams['uniacid']));
  31. $keywordrow = array(
  32. 'rid' => $rid,
  33. 'uniacid' => intval($coverparams['uniacid']),
  34. 'module' => 'cover',
  35. 'status' => 1,
  36. 'displayorder' => 0,
  37. 'type' => 1,
  38. 'content' => safe_gpc_string($coverparams['keyword']),
  39. );
  40. table('rule_keyword')->fill($keywordrow)->save();
  41. }
  42. $entry = array(
  43. 'uniacid' => intval($coverparams['uniacid']),
  44. 'multiid' => intval($coverparams['multiid']),
  45. 'rid' => $rid,
  46. 'title' => safe_gpc_string($coverparams['title']),
  47. 'description' => safe_gpc_string($coverparams['description']),
  48. 'thumb' => safe_gpc_path($coverparams['thumb']),
  49. 'url' => safe_gpc_url($coverparams['url']),
  50. 'do' => '',
  51. 'module' => safe_gpc_string($coverparams['module']),
  52. );
  53. if (empty($cover['id'])) {
  54. $coverreply_table->fill($entry)->save();
  55. } else {
  56. $coverreply_table->fill($entry)->whereId($cover['id'])->save();
  57. }
  58. return true;
  59. }
  60. function site_cover_delete($page_id) {
  61. global $_W;
  62. $page_id = intval($page_id);
  63. $coverreply_table = table('core_cover_reply');
  64. $coverreply_table->searchWithMultiid($page_id);
  65. $cover = $coverreply_table->getByModuleAndUniacid('page', $_W['uniacid']);
  66. if(!empty($cover)) {
  67. $rid = intval($cover['rid']);
  68. uni_delete_rule($rid, 'cover_reply');
  69. }
  70. return true;
  71. }
  72. function site_ip_validate($ip) {
  73. $ip = trim($ip);
  74. if (empty($ip)) {
  75. return error(-1, 'ip不能为空');
  76. }
  77. $ip_data = explode("\n", $ip);
  78. foreach ($ip_data as $ip) {
  79. if (!filter_var($ip, FILTER_VALIDATE_IP)) {
  80. return error(-1, $ip . '不合法');
  81. }
  82. if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
  83. return error(-1, $ip . '为外网ip,外网ip不可填');
  84. }
  85. }
  86. return $ip_data;
  87. }
  88. function site_ip_add($ip = '') {
  89. load()->model('setting');
  90. $ip_data = site_ip_validate($ip);
  91. if (is_error($ip_data)) {
  92. return error(-1, $ip_data['message']);
  93. }
  94. $ip_data_format = setting_load('ip_white_list');
  95. $ip_data_format = $ip_data_format['ip_white_list'];
  96. foreach ($ip_data as $ip) {
  97. $ip_data_format[$ip]['ip'] = $ip;
  98. $ip_data_format[$ip]['status'] = 1;
  99. }
  100. return setting_save($ip_data_format, 'ip_white_list');
  101. }