setting.mod.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 setting_save($data = '', $key = '') {
  8. if (empty($data) && empty($key)) {
  9. return FALSE;
  10. }
  11. if (is_array($data) && empty($key)) {
  12. foreach ($data as $key => $value) {
  13. $record[] = "('$key', '" . iserializer($value) . "')";
  14. }
  15. if ($record) {
  16. $return = pdo_query("REPLACE INTO " . tablename('core_settings') . " (`key`, `value`) VALUES " . implode(',', $record));
  17. }
  18. } else {
  19. $return = pdo_insert('core_settings', array('key'=> $key, 'value' => iserializer($data)), TRUE);
  20. }
  21. $cachekey = cache_system_key('setting');
  22. cache_write($cachekey, '');
  23. return $return;
  24. }
  25. function setting_load($key = '') {
  26. global $_W;
  27. $cachekey = cache_system_key('setting');
  28. $settings = cache_load($cachekey);
  29. if (empty($settings)) {
  30. $settings = pdo_getall('core_settings', array(), array(), 'key');
  31. if (is_array($settings)) {
  32. foreach ($settings as $k => &$v) {
  33. $settings[$k] = iunserializer($v['value']);
  34. }
  35. }
  36. cache_write($cachekey, $settings);
  37. }
  38. if (!is_array($_W['setting'])) {
  39. $_W['setting'] = array();
  40. }
  41. $_W['setting'] = array_merge($settings, $_W['setting']);
  42. if (!empty($key)) {
  43. return array($key => $settings[$key]);
  44. } else {
  45. return $settings;
  46. }
  47. }
  48. function setting_upgrade_version($family, $version, $release) {
  49. $verfile = IA_ROOT . '/framework/version.inc.php';
  50. $verdat = <<<VER
  51. <?php
  52. /**
  53. * [WeEngine System] Copyright (c) 2014 WE7.CC
  54. * WeEngine is NOT a free software, it under the license terms, visited http://www.w7.cc/ for more details.
  55. */
  56. defined('IN_IA') or exit('Access Denied');
  57. define('IMS_FAMILY', "{$family}");
  58. define('IMS_VERSION', "{$version}");
  59. define('IMS_RELEASE_DATE', "{$release}");
  60. VER;
  61. return file_put_contents($verfile, trim($verdat));
  62. }