phoneapp.mod.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. defined('IN_IA') or exit('Access Denied');
  3. function phoneapp_support_modules() {
  4. global $_W;
  5. load()->model('user');
  6. $modules = user_modules($_W['uid']);
  7. $phoneapp_modules = array();
  8. if (!empty($modules)) {
  9. foreach ($modules as $module) {
  10. if ($module['phoneapp_support'] == MODULE_SUPPORT_PHONEAPP) {
  11. $phoneapp_modules[$module['name']] = $module;
  12. }
  13. }
  14. }
  15. return $phoneapp_modules;
  16. }
  17. function phoneapp_get_some_lastversions($uniacid) {
  18. load()->model('miniapp');
  19. $version_lasts = array();
  20. $uniacid = intval($uniacid);
  21. if (empty($uniacid)) {
  22. return $version_lasts;
  23. }
  24. $version_lasts = table('wxapp_versions')->latestVersion($uniacid);
  25. $last_switch_version = miniapp_last_switch_version($uniacid);
  26. if (!empty($last_switch_version[$uniacid]) && !empty($version_lasts[$last_switch_version[$uniacid]['version_id']])) {
  27. $version_lasts[$last_switch_version[$uniacid]['version_id']]['current'] = true;
  28. } else {
  29. reset($version_lasts);
  30. $firstkey = key($version_lasts);
  31. $version_lasts[$firstkey]['current'] = true;
  32. }
  33. return $version_lasts;
  34. }
  35. function phoneapp_version_by_version($version) {
  36. global $_W;
  37. if (empty($version)) {
  38. return array();
  39. }
  40. $version_info = table('wxapp_versions')->getByUniacidAndVersion($_W['uniacid'], $version);
  41. if (empty($version_info['id'])) {
  42. return array();
  43. } else {
  44. return phoneapp_version($version_info['id']);
  45. }
  46. }
  47. function phoneapp_version($version_id) {
  48. $version_info = array();
  49. $version_id = intval($version_id);
  50. if (empty($version_id)) {
  51. return $version_info;
  52. }
  53. $version_info = table('wxapp_versions')->getById($version_id);
  54. if (is_array($version_info['modules'])) {
  55. $uni_modules = uni_modules_by_uniacid($version_info['uniacid']);
  56. $uni_modules = array_keys($uni_modules);
  57. foreach ($version_info['modules'] as $i => $module) {
  58. if (!in_array($module['name'], $uni_modules)) {
  59. unset($version_info['modules'][$i]);
  60. continue;
  61. }
  62. $module_info = module_fetch($module['name']);
  63. $module_info['version'] = $module['version'];
  64. $module['uniacid'] = table('uni_link_uniacid')->getMainUniacid($version_info['uniacid'], $module['name'], $version_id);
  65. if (!empty($module['uniacid'])) {
  66. $module_info['uniacid'] = $module['uniacid'];
  67. $link_account = uni_fetch($module['uniacid']);
  68. $module_info['account'] = $link_account->account;
  69. $module_info['account']['logo'] = $link_account->logo;
  70. }
  71. $version_info['modules'][$i] = $module_info;
  72. }
  73. }
  74. return $version_info;
  75. }
  76. function phoneapp_getpackage($data, $if_single = false) {
  77. load()->classs('cloudapi');
  78. $api = new CloudApi();
  79. $response = $api->post('phoneapp', 'download', $data, 'binary');
  80. if ($response['code'] == 200) {
  81. return error(0, $response['content']);
  82. }
  83. return error(1, $response['content']);
  84. }
  85. function phoneapp_version_all($uniacid) {
  86. load()->model('module');
  87. $phoneapp_versions = array();
  88. $uniacid = intval($uniacid);
  89. if (empty($uniacid)) {
  90. return $phoneapp_versions;
  91. }
  92. $phoneapp_versions = table('wxapp_versions')->getAllByUniacid($uniacid);
  93. if (!empty($phoneapp_versions)) {
  94. foreach ($phoneapp_versions as &$version) {
  95. $version = phoneapp_version($version['id']);
  96. }
  97. }
  98. return $phoneapp_versions;
  99. }