| Current Path : /home/antonen/poznajlitwe.lt/media/com_aimysitemap/ |
| Current File : /home/antonen/poznajlitwe.lt/media/com_aimysitemap/crawl.js |
/*
* Copyright (c) 2017-2019 Aimy Extensions, Netzum Sorglos Software GmbH
* Copyright (c) 2014-2017 Aimy Extensions, Lingua-Systems Software GmbH
*
* https://www.aimy-extensions.com/
*
* License: GNU GPLv2, see LICENSE.txt within distribution and/or
* https://www.aimy-extensions.com/software-license.html
*/
g_aimysitemap_abort=false;function AimySitemapCrawl(i18n,token,outSel,cb) {var $out=jQuery(outSel);var urls={'manage':'index.php?option=com_aimysitemap&view=urls','crawl':'index.php?option=com_aimysitemap&task=crawl.crawl_ajax','init':'index.php?option=com_aimysitemap&task=crawl.crawl_init_ajax'};$out.html(jQuery('<div></div>') .addClass('row-fluid') .html(jQuery('<div></div>') .addClass('span6') .attr('id','report') .html(jQuery('<h2></h2>').text(i18n.crawling)) .append(jQuery('<div></div>') .css('margin','12px 0') .html(jQuery('<img></img>') .attr('src','../media/com_aimysitemap/progress.gif')) .append(jQuery('<p></p>') .css('padding','12px 0') .html(jQuery('<strong></strong>') .text(i18n.dont_close)))) .append(jQuery('<div></div>') .css('overflow','hidden') .attr('id','progress') .html(jQuery('<div></div>') .addClass('alert alert-info') .text(i18n.init)))) .append(jQuery('<div></div>') .addClass('span6') .attr('id','wait')));var $progress=jQuery('#progress');var $wait=jQuery('#wait');var $report=jQuery('#report');var wait={ival:null,cur:0,max:2};var crawl_cnt=0;var retry={cur:0,max:30,sleep:10};var post_data={};post_data[token]=1;var respToJson=function(jd) {if(jd&&typeof(jd)=='string') {try {jd=jQuery.parseJSON(jd);} catch(e){}} return jd;};var update_wait=function() {wait.cur=wait.cur+1>wait.max?1:wait.cur+1;$wait .hide() .html(jQuery('<p></p>') .css('text-align','center') .html(jQuery('<img></img>') .attr({'src':'../media/com_aimysitemap/wait-'+ wait.cur+'.jpg?r=24.3','width':400,'height':469,'alt':'Wait on Crawl'}))) .fadeIn('slow');};var mark_fail=function(ctx,msg) {if(wait.ival) {window.clearInterval(wait.ival);} $out.html(jQuery('<div></div>') .addClass('alert alert-danger') .text((ctx?(ctx+': '):'')+(msg?msg:'')));if(typeof(cb)=='function') {cb(false,msg);} return false;};var report_list=function(n,l,ic) {var $ul=jQuery('<ul></ul>');for(i=0;i<l.length;i++) {$ul.append(jQuery('<li></li>').text(l[i]));} $report.append(jQuery('<div></div>') .addClass('alert alert-info') .html(jQuery('<h3></h3>') .addClass('alert-heading') .text(n+': '+l.length) .prepend(jQuery('<i></i>') .addClass('icon icon-'+ic) .css('padding-right','12px'))) .append($ul) .fadeIn(600));};var generate_report=function(jd) {window.clearInterval(wait.ival);$wait.fadeOut('fast');if(!'ok'in jd||!jd.ok) {return mark_fail('crawl-abort',('msg'in jd?jd.msg:'Unspecified error from backend - please have a look '+ 'at your PHP error log and contact Aimy Extensions\' '+ 'support. Thanks in advance!'));} if(crawl_cnt<=3) {$report.html($progress.append(jQuery('<div></div>') .addClass('padded-tb') .html(jQuery('<div></div>') .addClass('alert alert-danger') .text(i18n.abort_first))));if(typeof(cb)=='function') {cb(false,i18n.abort_first);} return;} $progress.find('div:not(.alert)').remove();if($progress.find('div.alert.alert-danger').length) {$wait.html($progress.html()) .prepend(jQuery('<h2></h2>') .text(i18n.errors) .append(jQuery('<i></i>') .addClass('icon icon-warning') .css({'color':'#800','padding-left':'8px'}))) .fadeIn(600);$wait.find('div.alert').show().css('opacity',1);} $report.html(jQuery('<h2></h2>') .text(i18n.finished) .append(jQuery('<i></i>') .addClass('icon icon-ok') .css({'color':'#390','padding-left':'8px'})));if('msg'in jd) {$report.append(jQuery('<div></div>') .addClass('alert alert-info') .text(jd.msg));} if('stats'in jd) {var changed=false;var s=jd.stats;if('added'in s&&s.added.length>0) {changed=true;report_list(i18n.added,s.added,'plus-2');} if('deleted'in s&&s.deleted.length>0) {changed=true;report_list(i18n.deleted,s.deleted,'minus-2');} if('updated'in s&&s.updated.length>0) {changed=true;report_list(i18n.updated,s.updated,'loop');} if(!changed) {$report.append(jQuery('<div></div>') .addClass('alert alert-info') .text(i18n.no_updates));}} $report.append(jQuery('<div></div>') .addClass('row-fluid') .html(jQuery('<a></a>') .addClass('btn btn-lg btn-primary') .attr('href',urls.manage) .text(i18n.manage+'!')));if(typeof(cb)=='function') {cb(true,i18n.finished);}};var show_url_result=function(jd) {var $res=jQuery('<div></div>') .css('margin','4px 0') .html(jQuery('<code></code>') .text(jd.url));if(!('rebuilding'in jd)) {if('ok'in jd&&jd.ok) {$res.append(jQuery('<i></i>') .addClass('icon icon-ok') .css('padding-left','4px'));} else {$res.addClass('alert alert-danger') .append(jQuery('<i></i>') .addClass('icon icon-delete') .css('padding','0 4px'));}} if('msg'in jd) {$res.append(jQuery('<strong></strong>') .text(' '+jd.msg));} $progress.prepend($res.fadeIn(600));if('ok'in jd&&jd.ok&&!('rebuilding'in jd)) {$res.delay('msg'in jd?8000:4000) .fadeOut(600,function(){$res.remove();});}};var crawl_next=function() {if(g_aimysitemap_abort) {return mark_fail('userabort',i18n.userabort);} jQuery.post(urls.crawl,post_data,function(jd) {crawl_cnt++;jd=respToJson(jd);if(retry.cur!=0) {retry.cur=0;$progress.find('.crawl-request-fail') .fadeOut(1200,function(){jQuery(this).remove();});} if(jd!==null&&typeof(jd)=='object') {if('abort'in jd&&jd.abort) {return generate_report(jd);} show_url_result(jd);if('rebuilding'in jd&&jd.rebuilding) {return;} return crawl_next();} else {return mark_fail('crawl','Unspecified error from backend - '+ 'please have a look at your PHP error log and contact '+ 'Aimy Extensions\' support. Thanks in advance!');}}) .fail(function() {if(retry.cur<retry.max) {retry.cur++;$progress.prepend(jQuery('<div></div>') .addClass('alert alert-notice crawl-request-fail') .text(i18n.retry+ ' ('+retry.cur+'/'+retry.max+')'));window.setTimeout(function(){crawl_next();},retry.sleep*1000);} else {return mark_fail('crawl-request','Could not communicate with backend');}});};jQuery.post(urls.init,post_data,function(jd) {crawl_cnt++;jd=respToJson(jd);if(jd!==null&&typeof(jd)=='object') {if('ok'in jd&&jd.ok) {$progress.html('');update_wait();wait.ival=window.setInterval(function(){update_wait();},10000);show_url_result(jd);crawl_next();} else {return mark_fail('crawl-init','msg'in jd?jd.msg:'Initializing the crawler failed - '+ 'please have a look at your PHP error log and '+ 'contact Aimy Extensions\' support. Thanks in '+ 'advance!');}} else {return mark_fail('crawl-init','Invalid result from backend - '+ 'please have a look at your PHP error log and contact '+ 'Aimy Extensions\' support. Thanks in advance!');}}) .fail(function(xhr) {var err=null;try {var jd=jQuery.parseJSON(xhr.responseText);if('msg'in jd) {err=jd.msg;}} catch(e){} if(!err) {try {err=jQuery('<span></span>').html(xhr.responseText).text();} catch(e){}} return mark_fail('crawl-init-request','Could not communicate with backend' +(err?(': '+err):''));});}