function isCurlInstalled() { if (in_array('curl', get_loaded_extensions())) { return true; } else { return false; } } // -1 - cannot get version info // 0 - current // + - newer is avaialble, version is returned function checkVersionInfo($downloadid, $version) { if (!isset($downloadid)): return -1; endif; try { $call = "http://blog.dragonsoft.us/downloadversion/" . $downloadid; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $call); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_MAXREDIRS, 1); $output=curl_exec($ch); $json = json_decode($output); if ($json->id == $downloadid): $newversion = $json->version; if ($json->version > $version): return $json->version; else: return 0; endif; else: return -1; endif; } catch (Exception $e) { return -1; } } if ($is_module): $admin_info = new ArrayObject(parse_ini_file(MODPATH . $name . "/module.info"), ArrayObject::ARRAY_AS_PROPS); $version = number_format($admin_info->version / 10, 1, '.', ''); $lastupdate = module::get_var($name, "last_update", time()); $checkInDays = module::get_var($name, "auto_delay", 30); else: $admin_info = new ArrayObject(parse_ini_file(THEMEPATH . $name . "/theme.info"), ArrayObject::ARRAY_AS_PROPS); $version = $admin_info->version; $lastupdate = module::get_var("th_" . $name, "last_update", time()); $checkInDays = module::get_var("th_" . $name, "auto_delay", 30); endif; if (isCurlInstalled() && ($checkInDays > 0) && ((time() - $lastupdate) > ($checkInDays * 24 * 60 * 60))): // Check version every N days $admin_info2 = new ArrayObject(parse_ini_file(MODPATH . "greydragon/module.info"), ArrayObject::ARRAY_AS_PROPS); $version2 = number_format($admin_info2->version / 10, 1, '.', ''); $versionCheck = checkVersionInfo($downloadid, $version); $versionCheck2 = checkVersionInfo(15, $version2); if (($versionCheck == 0) && ($versionCheck2 == 0)): if ($is_module): module::set_var($name, "last_update", time()); else: module::set_var("th_" . $name, "last_update", time()); endif; endif; else: $versionCheck = 0; $versionCheck2 = 0; endif; ?>