app.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /*
  3. [UCenter] (C)2001-2099 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: app.php 1059 2011-03-01 07:25:09Z monkey $
  6. */
  7. !defined('IN_UC') && exit('Access Denied');
  8. class appmodel {
  9. var $db;
  10. var $base;
  11. function __construct(&$base) {
  12. $this->appmodel($base);
  13. }
  14. function appmodel(&$base) {
  15. $this->base = $base;
  16. $this->db = $base->db;
  17. }
  18. function get_apps($col = '*', $where = '') {
  19. $arr = $this->db->fetch_all("SELECT $col FROM ".UC_DBTABLEPRE."applications".($where ? ' WHERE '.$where : ''), 'appid');
  20. foreach($arr as $k => $v) {
  21. isset($v['extra']) && !empty($v['extra']) && $v['extra'] = unserialize($v['extra']);
  22. if($tmp = $this->base->authcode($v['authkey'], 'DECODE', UC_MYKEY)) {
  23. $v['authkey'] = $tmp;
  24. }
  25. $arr[$k] = $v;
  26. }
  27. return $arr;
  28. }
  29. function get_app_by_appid($appid, $includecert = FALSE) {
  30. $appid = intval($appid);
  31. $arr = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."applications WHERE appid='$appid'");
  32. $arr['extra'] = unserialize($arr['extra']);
  33. if($tmp = $this->base->authcode($arr['authkey'], 'DECODE', UC_MYKEY)) {
  34. $arr['authkey'] = $tmp;
  35. }
  36. if($includecert) {
  37. $this->load('plugin');
  38. $certfile = $_ENV['plugin']->cert_get_file();
  39. $appdata = $_ENV['plugin']->cert_dump_decode($certfile);
  40. if(is_array($appdata[$appid])) {
  41. $arr += $appdata[$appid];
  42. }
  43. }
  44. return $arr;
  45. }
  46. function delete_apps($appids) {
  47. $appids = $this->base->implode($appids);
  48. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."applications WHERE appid IN ($appids)");
  49. return $this->db->affected_rows();
  50. }
  51. function alter_app_table($appid, $operation = 'ADD') {
  52. if($operation == 'ADD') {
  53. $this->db->query("ALTER TABLE ".UC_DBTABLEPRE."notelist ADD COLUMN app$appid tinyint NOT NULL", 'SILENT');
  54. } else {
  55. $this->db->query("ALTER TABLE ".UC_DBTABLEPRE."notelist DROP COLUMN app$appid", 'SILENT');
  56. }
  57. }
  58. function test_api($url, $ip = '') {
  59. $this->base->load('misc');
  60. if(!$ip) {
  61. $ip = $_ENV['misc']->get_host_by_url($url);
  62. }
  63. if($ip < 0) {
  64. return FALSE;
  65. }
  66. return $_ENV['misc']->dfopen($url, 0, '', '', 1, $ip);
  67. }
  68. }
  69. ?>