credit.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. /*
  3. [UCenter] (C)2001-2099 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: credit.php 1059 2011-03-01 07:25:09Z monkey $
  6. */
  7. !defined('IN_UC') && exit('Access Denied');
  8. class control extends adminbase {
  9. function __construct() {
  10. $this->control();
  11. }
  12. function control() {
  13. parent::__construct();
  14. $this->check_priv();
  15. if(!$this->user['isfounder'] && !$this->user['allowadmincredits']) {
  16. $this->message('no_permission_for_this_module');
  17. }
  18. }
  19. function onls() {
  20. $appsrc = getgpc('appsrc', 'P');
  21. $creditsrc = getgpc('creditsrc', 'P');
  22. $appdesc = getgpc('appdesc', 'P');
  23. $creditdesc = getgpc('creditdesc', 'P');
  24. $ratiosrc = getgpc('ratiosrc', 'P');
  25. $ratiodesc = getgpc('ratiodesc', 'P');
  26. $delete = getgpc('delete', 'P');
  27. $addexchange = getgpc('addexchange', 'G');
  28. $delexchange = getgpc('delexchange', 'G');
  29. $settings = $this->get_setting(array('creditexchange'), TRUE);
  30. $creditexchange = is_array($settings['creditexchange']) ? $settings['creditexchange'] : array();
  31. $appsrc = @intval($appsrc);
  32. $creditsrc = @intval($creditsrc);
  33. $appdesc = @intval($appdesc);
  34. $creditdesc = @intval($creditdesc);
  35. $ratiosrc = ($ratiosrc = @intval($ratiosrc)) > 0 ? $ratiosrc : 1;
  36. $ratiodesc = ($ratiodesc = @intval($ratiodesc)) > 0 ? $ratiodesc : 1;
  37. if(!empty($addexchange) && $this->submitcheck()) {
  38. if($appsrc != $appdesc) {
  39. $key = $appsrc.'_'.$creditsrc.'_'.$appdesc.'_'.$creditdesc;
  40. $creditexchange[$key] = $ratiosrc."\t".$ratiodesc;
  41. $this->set_setting('creditexchange', $creditexchange, TRUE);
  42. $this->load('cache');
  43. $_ENV['cache']->updatedata('settings');
  44. $status = 1;
  45. $this->writelog('credit_addexchange', $appsrc.'_'.$creditsrc.' : '.$appdesc.'_'.$creditdesc.'='.$ratiosrc.' : '.$ratiodesc);
  46. } else {
  47. $status = -1;
  48. }
  49. $settings = $this->get_setting(array('creditexchange'), TRUE);
  50. $creditexchange = is_array($settings['creditexchange']) ? $settings['creditexchange'] : array();
  51. } elseif(!empty($delexchange) && $this->submitcheck()) {
  52. if(is_array($delete)) {
  53. foreach($delete as $key) {
  54. unset($creditexchange[$key]);
  55. }
  56. $this->set_setting('creditexchange', $creditexchange, TRUE);
  57. $this->load('cache');
  58. $_ENV['cache']->updatedata('settings');
  59. $status = 1;
  60. $this->writelog('credit_deleteexchange', "delete=".implode(',', $delete));
  61. }
  62. $settings = $this->get_setting(array('creditexchange'), TRUE);
  63. $creditexchange = is_array($settings['creditexchange']) ? $settings['creditexchange'] : array();
  64. }
  65. $apps = unserialize($this->settings['credits']);
  66. if(is_array($creditexchange)) {
  67. foreach($creditexchange as $set => $ratio) {
  68. $tmp = array();
  69. list($tmp['appsrc'], $tmp['creditsrc'], $tmp['appdesc'], $tmp['creditdesc']) = explode('_', $set);
  70. list($tmp['ratiosrc'], $tmp['ratiodesc']) = explode("\t", $ratio);
  71. $tmp['creditsrc'] = $apps[$tmp['appsrc']][$tmp['creditsrc']][0];
  72. $tmp['creditdesc'] = $apps[$tmp['appdesc']][$tmp['creditdesc']][0];
  73. $tmp['appsrc'] = $this->cache['apps'][$tmp['appsrc']]['name'];
  74. $tmp['appdesc'] = $this->cache['apps'][$tmp['appdesc']]['name'];
  75. $creditexchange[$set] = $tmp;
  76. }
  77. }
  78. $appselect = '';
  79. if(is_array($apps)) {
  80. foreach($apps as $appid => $credits) {
  81. $appselect .= '<option value="'.$appid.'">'.$this->cache['apps'][$appid]['name'].'</option>';
  82. $tmp = array();
  83. if(is_array($credits)) {
  84. foreach($credits as $id => $credit) {
  85. $tmp[] = '['.$id.', \''.str_replace('\'', '\\\'', $credit[0]).'\']';
  86. }
  87. }
  88. $creditselect[$appid] = 'credit['.$appid.'] = ['.implode(',', $tmp).'];';
  89. }
  90. }
  91. $this->view->assign('status', $status);
  92. $this->view->assign('appsrc', $appsrc);
  93. $this->view->assign('creditsrc', $creditsrc);
  94. $this->view->assign('appdesc', $appdesc);
  95. $this->view->assign('creditdesc', $creditdesc);
  96. $this->view->assign('ratiosrc', $ratiosrc);
  97. $this->view->assign('ratiodesc', $ratiodesc);
  98. $this->view->assign('appselect', $appselect);
  99. $this->view->assign('creditselect', $creditselect);
  100. $this->view->assign('creditexchange', $creditexchange);
  101. $this->view->display('admin_credit');
  102. }
  103. function onsync() {
  104. $this->load('note');
  105. $this->load('misc');
  106. $this->load('cache');
  107. $step = intval(getgpc('step', 'G'));
  108. if(!$step && is_array($this->cache['apps'])) {
  109. $credits = array();
  110. $stepapp = intval(getgpc('stepapp', 'G'));
  111. $testrelease = intval(getgpc('testrelease', 'G'));
  112. $appids = array_keys($this->cache['apps']);
  113. $appid = $appids[$stepapp];
  114. if(!$stepapp) {
  115. $_CACHE['credits'] = array();
  116. } else {
  117. include UC_DATADIR.'cache/credits.php';
  118. }
  119. if($app = $this->cache['apps'][$appid]) {
  120. $apifilename = isset($app['apifilename']) && $app['apifilename'] ? $app['apifilename'] : 'uc.php';
  121. if($app['extra']['apppath'] && @include $app['extra']['apppath'].'./api/'.$apifilename) {
  122. $uc_note = new uc_note();
  123. $data = trim($uc_note->getcreditsettings('', ''));
  124. } else {
  125. $url = $_ENV['note']->get_url_code('getcreditsettings', '', $appid);
  126. $data = trim($_ENV['misc']->dfopen($url, 0, '', '', 1));
  127. }
  128. if(!$testrelease) {
  129. if(!($data = $this->sync_unserialize($data, ''))) {
  130. header('location: '.UC_API.'/admin.php?m=credit&a=sync&step=0&stepapp='.$stepapp.'&testrelease=1&sid='.$this->view->sid);
  131. exit();
  132. } else {
  133. $stepapp++;
  134. }
  135. } else {
  136. $data = $this->sync_unserialize($data, 'release/20080429/');
  137. $stepapp++;
  138. }
  139. if($data) {
  140. $_CACHE['credits'][$appid] = $data;
  141. $s = "<?php\r\n";
  142. $s .= '$_CACHE[\'credits\'] = '.var_export($_CACHE['credits'], TRUE).";\r\n";
  143. $s .= "\r\n?>";
  144. $fp = @fopen(UC_DATADIR.'cache/credits.php', 'w');
  145. @fwrite($fp, $s);
  146. @fclose($fp);
  147. }
  148. header('location: '.UC_API.'/admin.php?m=credit&a=sync&step=0&stepapp='.$stepapp.'&sid='.$this->view->sid);
  149. } else {
  150. header('location: '.UC_API.'/admin.php?m=credit&a=sync&step=1&sid='.$this->view->sid);
  151. }
  152. exit();
  153. }
  154. include_once UC_DATADIR.'cache/credits.php';
  155. $credits = $_CACHE['credits'];
  156. $this->set_setting('credits', $credits, TRUE);
  157. $this->load('cache');
  158. $_ENV['cache']->updatedata('settings');
  159. $this->writelog('credit_sync', 'succeed');
  160. $settings = $this->get_setting(array('creditexchange'), TRUE);
  161. $creditexchange = is_array($settings['creditexchange']) ? $settings['creditexchange'] : array();
  162. $updaterequest = array();
  163. $i = 0;
  164. foreach($creditexchange as $set => $ratio) {
  165. $tmp = array();
  166. list($tmp['appsrc'], $tmp['creditsrc'], $tmp['appdesc'], $tmp['creditdesc']) = explode('_', $set);
  167. list($tmp['ratiosrc'], $tmp['ratiodesc']) = explode("\t", $ratio);
  168. $updaterequest[$tmp['appsrc']][] =
  169. '&credit['.$tmp['appsrc'].']['.$i.'][creditsrc]='.intval($tmp['creditsrc']).
  170. '&credit['.$tmp['appsrc'].']['.$i.'][appiddesc]='.urlencode($tmp['appdesc']).
  171. '&credit['.$tmp['appsrc'].']['.$i.'][creditdesc]='.intval($tmp['creditdesc']).
  172. '&credit['.$tmp['appsrc'].']['.$i.'][title]='.urlencode($this->cache['apps'][$tmp['appdesc']]['name'].' '.$credits[$tmp['appdesc']][$tmp['creditdesc']][0]).
  173. '&credit['.$tmp['appsrc'].']['.$i.'][unit]='.urlencode($credits[$tmp['appdesc']][$tmp['creditdesc']][1]).
  174. '&credit['.$tmp['appsrc'].']['.$i.'][ratiosrc]='.$tmp['ratiosrc'].
  175. '&credit['.$tmp['appsrc'].']['.$i.'][ratiodesc]='.$tmp['ratiodesc'].
  176. '&credit['.$tmp['appsrc'].']['.$i.'][ratio]='.($tmp['ratiosrc'] / $tmp['ratiodesc']);
  177. $i++;
  178. }
  179. $data = array();
  180. foreach($updaterequest as $appid => $value) {
  181. $data[] = implode('', $updaterequest[$appid]);
  182. }
  183. $_ENV['note']->add('updatecreditsettings', implode('', $data));
  184. $_ENV['note']->send();
  185. $this->message('syncappcredits_updated','admin.php?m=credit&a=ls');
  186. }
  187. function sync_unserialize($s, $release_root) {
  188. if(!function_exists('xml_unserialize')) {
  189. if($release_root && file_exists(UC_ROOT.$release_root.'./lib/xml.class.php')) {
  190. include UC_ROOT.$release_root.'./lib/xml.class.php';
  191. } else {
  192. include UC_ROOT.'./lib/xml.class.php';
  193. }
  194. }
  195. return xml_unserialize($s);
  196. }
  197. }
  198. ?>