XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
updates.php
Go to the documentation of this file.
1 <?php
2 // $Id: blocks.php 1037 2012-09-07 21:19:12Z i.bitcero $
3 // --------------------------------------------------------------
4 // Red México Common Utilities
5 // A framework for Red México Modules
6 // Author: Eduardo Cortés <i.bitcero@gmail.com>
7 // Email: i.bitcero@gmail.com
8 // License: GPL 2.0
9 // --------------------------------------------------------------
10 
11 include dirname(dirname(dirname(dirname(__FILE__)))).'/mainfile.php';
12 $xoopsLogger->activated = false;
13 
14 set_time_limit(0);
15 
16 // Get modules
17 $sql = "SELECT * FROM ".$xoopsDB->prefix("modules")." WHERE isactive=1";
18 $result = $xoopsDB->query($sql);
19 
20 $urls = array();
21 $modNames = array();
22 
23 while($row = $xoopsDB->fetchArray($result)){
24  $mod = new XoopsModule();
25  $mod->assignVars($row);
26 
27  $info = $mod->getInfo();
28 
29  if(!isset($info['rmversion'])) continue;
30  if(!isset($info['updateurl'])) continue;
31 
32  $modNames[$mod->dirname()] = $info['name'];
33  $v = $info['rmversion'];
34 
35  if(isset($v['major']))
36  $version = $v['major'].'.'.$v['minor'].'.'.($v['revision']/10).'.'.$v['stage'];
37  else
38  $version = $v['number'].'.'.($v['revision']/100).'.'.$v['status'];
39 
40  $urls[$mod->dirname()] = strpos($info['updateurl'], '?')===false ? $info['updateurl'].'?version='.$version : $info['updateurl'].'&version='.$version;
41 
42 }
43 
44 $total = 0;
45 $upds = array();
46 foreach($urls as $dir => $url){
47  $ret = file_get_contents($url);
48  $ret = json_decode($ret, true);
49  if($ret['message']==0) continue;
50  if($ret['error']==1) continue;
51 
52  $ret['data']['type'] = 'module';
53  $ret['data']['dir'] = $dir;
54  $ret['data']['name'] = $modNames[$dir];
55  $upds[] = $ret;
56 
57  $total++;
58 }
59 
61 $urls = array();
62 $plugNames = array();
63 // Check updates for plugins
64 $result = $xoopsDB->query("SELECT dir FROM ".$xoopsDB->prefix("rmc_plugins"));
65 while($row = $xoopsDB->fetchArray($result)){
66  $plugin = $rmFunc->load_plugin($row['dir']);
67  if(!$plugin) continue;
68 
69  $info = $plugin->info();
70 
71  if(!isset($info['updateurl'])) continue;
72 
73  $plugNames[$row['dir']] = $info['name'];
74  $v = $info['version'];
75 
76  if(!is_array($v))
77  $version = '0.0.0.0';
78  else
79  $version = $v['major'].'.'.$v['minor'].'.'.($v['revision']/10).'.'.$v['stage'];
80 
81  $urls[$row['dir']] = strpos($info['updateurl'], '?')===false ? $info['updateurl'].'?version='.$version : $info['updateurl'].'&version='.$version;
82 
83 }
84 
85 foreach($urls as $dir => $url){
86  $ret = file_get_contents($url);
87  $ret = json_decode($ret, true);
88  if($ret['message']==0) continue;
89  if($ret['error']==1) continue;
90 
91  $ret['data']['type'] = 'plugin';
92  $ret['data']['dir'] = $dir;
93  $ret['data']['name'] = $plugNames[$dir];
94  $upds[] = $ret;
95 
96  $total++;
97 }
98 
99 file_put_contents(XOOPS_CACHE_PATH.'/updates.chk', base64_encode(serialize(array('date'=>time(),'total'=>$total,'updates'=>$upds))));
100 
101 header('Cache-Control: no-cache, must-revalidate');
102 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
103 header('Content-type: application/json');
104 echo json_encode(array('total'=>$total));
105 die();