fixes update check performance ...

This commit is contained in:
Abdulrahman
2019-01-31 20:03:35 +03:00
parent eca2a15446
commit c565d4f8df
6 changed files with 99 additions and 76 deletions

View File

@@ -7,7 +7,30 @@
<li class="breadcrumb-item active">{lang.R_CHECK_UPDATE}</li>
</ol>
<div class="alert <IF NAME="error">alert-warning<ELSE>alert-info</IF>">{text}</div>
<div id="updateInfo" class="alert">
<img src="{STYLE_PATH_ADMIN}images/ajax-loader-small.gif" />
</div>
<script>
setTimeout(function(){
$.ajax({
url: './?cp=p_check_update&smt=check&_ajax_=1',
dataType: 'json',
success: function (data) {
if(data.content){
var info = data.content.split(":::");
$('#updateInfo').html(info[1]).addClass(info[0] == 1 ? 'alert-warning' : 'alert-info');
} else {
this.fail();
}
<IF NAME="showMessage"> location.href = './?update_done=1'; </IF>
},
fail: function() {
$('#updateInfo').html('{lang.ERROR_CHECK_VER}').addClass('alert-warning');
<IF NAME="showMessage"> location.href = './?update_done=1'; </IF>
}
});
}, 300);
</script>
<ELSEIF NAME="current_smt == howto">

View File

@@ -24,25 +24,8 @@
<script type="text/javascript" src="{STYLE_PATH_ADMIN}js/jquery.waitforimages.js"></script>
</IF>
<IF NAME="go_to==start">
<script type="text/javascript">
$.ajax({url: "https://api.github.com/repos/awssat/kleeja/contributors",
dataType: 'json',
success: function (data) {
var template = $('#ghTemplate')[0].outerHTML;
$.each(data, function(i, item) {
$("#gtresults").append(template.replace('%id%', item['id']).replace('%login%', item['login']).replace('ghTemplate',
'gt'+item['id']).replace('%avatarUrl%', item['avatar_url']).replace('%contributions%', item['contributions']).replace('%htmlUrl%', item['html_url']));
$('#gt'+item['id']).removeAttr('style');
});
}
});
</script>
</IF>
<script type="text/javascript">
<!--//
$(function () {
//check for msg, reports every 5min
@@ -239,7 +222,6 @@ function confirm_form(r)
function get_kleeja_link(link) {
location.href = link;
}
//-->
</script>
</body>
</html>

View File

@@ -412,7 +412,24 @@
<br>
<hr>
<div class="text-muted text-center">Kleeja proudly made in Buraydah City <br> ❤ Trusted since 2007 <br><small>{kleeja_version}</small></div>
<script type="text/javascript">
setTimeout(function() {
$.ajax({
url: "https://api.github.com/repos/awssat/kleeja/contributors",
dataType: 'json',
success: function (data) {
var template = $('#ghTemplate')[0].outerHTML;
$.each(data, function (i, item) {
$("#gtresults").append(template.replace('%id%', item['id']).replace('%login%', item['login']).replace(
'ghTemplate',
'gt' + item['id']).replace('%avatarUrl%', item['avatar_url']).replace('%contributions%', item[
'contributions']).replace('%htmlUrl%', item['html_url']));
$('#gt' + item['id']).removeAttr('style');
});
}
});
}, 400);
</script>
</IF>

View File

@@ -439,7 +439,11 @@ if(!ig('_ajax_'))
else
{
$is_ajax = 'yes';
echo_ajax(1, $tpl->display($stylee, $styleePath), $go_menu_html);
echo_ajax(1,
empty($adminAjaxContent) ? $tpl->display($stylee, $styleePath) : $adminAjaxContent,
$go_menu_html
);
}
//footer

View File

@@ -15,57 +15,68 @@ if (!defined('IN_ADMIN'))
$stylee = "admin_check_update";
$current_smt = preg_replace('/[^a-z0-9_]/i', '', g('smt', 'str', 'general'));
$error = false;
$update_link = $config['siteurl'] . 'install/update.php?lang=' . $config['language'];
#to prevent getting the url data for all cats
if($current_smt == 'general'):
if($current_smt == 'check'):
//get data from kleeja database
$b_url = empty($_SERVER['SERVER_NAME']) ? $config['siteurl'] : $_SERVER['SERVER_NAME'];
$b_data = fetch_remote_file('https://raw.githubusercontent.com/awssat/kleeja/master/includes/version.php', false, 6);
//get data from kleeja github repo
if (! ($version_data = $cache->get('kleeja_repo_version')))
{
$github_data = fetch_remote_file('https://raw.githubusercontent.com/awssat/kleeja/master/includes/version.php', false, 6);
if (! empty($github_data))
{
preg_match_all('/define\(\'KLEEJA_VERSION\',\s{1,4}\'([^\']+)\'\);/', $github_data, $matches, PREG_SET_ORDER, 0);
$version_data = trim(htmlspecialchars($matches[0][1]));
$cache->save('kleeja_repo_version', $version_data, 3600 * 2);
}
}
$error = 0;
if ($b_data === false && !ig('show_msg'))
{
$text = $lang['ERROR_CHECK_VER'];
$error = true;
}
else
{
preg_match_all('/define\(\'KLEEJA_VERSION\',\s{1,4}\'([^\']+)\'\);/', $b_data, $matches, PREG_SET_ORDER, 0);
if (empty($matches[0][1]))
if(empty($version_data))
{
$text = $lang['ERROR_CHECK_VER'];
$error = true;
$error = 1;
}
}
if(!$error)
{
$version_data = trim(htmlspecialchars($matches[0][1]));
if (version_compare(strtolower(KLEEJA_VERSION), strtolower($version_data), '<'))
else
{
$text = sprintf($lang['UPDATE_NOW_S'] , KLEEJA_VERSION, strtolower($version_data)) . '<br /><br />' . $lang['UPDATE_KLJ_NOW'];
$error = true;
}
else if (version_compare(strtolower(KLEEJA_VERSION), strtolower($version_data), '='))
{
$text = $lang['U_LAST_VER_KLJ'];
}
else if (version_compare(strtolower(KLEEJA_VERSION), strtolower($version_data), '>'))
{
$text = $lang['U_USE_PRE_RE'];
if (version_compare(strtolower(KLEEJA_VERSION), strtolower($version_data), '<'))
{
$text = sprintf($lang['UPDATE_NOW_S'] , KLEEJA_VERSION, strtolower($version_data)) . '<br /><br />' . $lang['UPDATE_KLJ_NOW'];
$error = 1;
}
else if (version_compare(strtolower(KLEEJA_VERSION), strtolower($version_data), '='))
{
$text = $lang['U_LAST_VER_KLJ'];
}
else if (version_compare(strtolower(KLEEJA_VERSION), strtolower($version_data), '>'))
{
$text = $lang['U_USE_PRE_RE'];
}
}
//lets recore it
$v = @unserialize($config['new_version']);
$data = array(
'version_number' => $version_data,
'last_check' => time()
);
//To prevent expected error [ infinit loop ]
$data = serialize($data);
update_config('new_version', $SQL->real_escape($data), false);
delete_cache('data_config');
$adminAjaxContent = $error . ':::' . $text;
elseif($current_smt == 'general'):
// if(!$error)
// {
//To prevent expected error [ infinit loop ]
if(ig('show_msg'))
{
$query_get = array(
@@ -83,25 +94,11 @@ if(!$error)
}
}
$data = array(
'version_number' => $version_data,
'last_check' => time(),
'msg_appeared' => ig('show_msg') ? true : false
);
$data = serialize($data);
// }
update_config('new_version', $SQL->real_escape($data), false);
delete_cache('data_config');
}
$showMessage = ig('show_msg');
//then go back to start
if(ig('show_msg'))
{
redirect(basename(ADMIN_PATH) . '?update_done=1');
$SQL->close();
exit;
}
#end current_smt == general
endif;

View File

@@ -172,11 +172,11 @@ if(!empty($d_groups) && is_array($d_groups))
}
//
// if 3 days, lets check again !
// if 10 days, lets check again !
// rev: let's say cache is not refreshed, so we will redirect alots of time,
// so update_done will be good solution
//
if (empty($v['last_check']) || ((time() - $v['last_check']) > 259200 && !$v['msg_appeared'] && $_SERVER['SERVER_NAME'] != 'localhost' && !ig('update_done')))
if (empty($v['last_check']) || ((time() - $v['last_check']) > 3600 * 24 * 10 && $_SERVER['SERVER_NAME'] != 'localhost' && !ig('update_done')))
{
redirect(basename(ADMIN_PATH) . '?cp=p_check_update&amp;show_msg=1');
$SQL->close();