+ echo "<div class='wrap'><h2>$title</h2><noscript>$noscript</noscript><table cellpadding='5px'><thead><td>$name</td><td>$url</td><td>$posts</td><td>$comments</td><td>$action</td></thead>\n$rows</table></form></div>";
+ echo "
+ <script type='text/javascript'>
+ var strings = {cont:'$continue',stop:'$stop',stopping:'$stopping',authors:'$authors',nothing:'$nothing'};
+ var blogs = {};
+ function blog(i, title, mode, status){
+ this.blog = i;
+ this.mode = mode;
+ this.title = title;
+ this.status = status;
+ this.button = document.getElementById('submit'+this.blog);
+ };
+ blog.prototype = {
+ start: function() {
+ this.cont = true;
+ this.kick();
+ this.check();
+ },
+ kick: function() {
+ ++this.kicks;
+ var i = this.blog;
+ jQuery.post('admin.php?import=blogger&noheader=true',{blog:this.blog},function(text,result){blogs[i].kickd(text,result)});
+ },
+ check: function() {
+ ++this.checks;
+ var i = this.blog;
+ jQuery.post('admin.php?import=blogger&noheader=true&status=true',{blog:this.blog},function(text,result){blogs[i].checkd(text,result)});
+ },
+ kickd: function(text, result) {
+ if ( result == 'error' ) {
+ // TODO: exception handling
+ if ( this.cont )
+ setTimeout('blogs['+this.blog+'].kick()', 1000);
+ } else {
+ if ( text == 'done' ) {
+ this.stop();
+ this.done();
+ } else if ( text == 'nothing' ) {
+ this.stop();
+ this.nothing();
+ } else if ( text == 'continue' ) {
+ this.kick();
+ } else if ( this.mode = 'stopped' )
+ jQuery(this.button).attr('value', strings.cont);
+ }
+ --this.kicks;
+ },
+ checkd: function(text, result) {
+ if ( result == 'error' ) {
+ // TODO: exception handling
+ } else {
+ eval('this.status='+text);
+ jQuery('#pstat'+this.blog).empty().append(this.status.p1+'/'+this.status.p2);
+ jQuery('#cstat'+this.blog).empty().append(this.status.c1+'/'+this.status.c2);
+ this.update();
+ if ( this.cont || this.kicks > 0 )
+ setTimeout('blogs['+this.blog+'].check()', $interval);
+ }
+ --this.checks;
+ },
+ update: function() {
+ jQuery('#pind'+this.blog).width(((this.status.p1>0&&this.status.p2>0)?(this.status.p1/this.status.p2*jQuery('#pind'+this.blog).parent().width()):1)+'px');
+ jQuery('#cind'+this.blog).width(((this.status.c1>0&&this.status.c2>0)?(this.status.c1/this.status.c2*jQuery('#cind'+this.blog).parent().width()):1)+'px');
+ },
+ stop: function() {
+ this.cont = false;
+ },
+ done: function() {
+ this.mode = 'authors';
+ jQuery(this.button).attr('value', strings.authors);
+ },
+ nothing: function() {
+ this.mode = 'nothing';
+ jQuery(this.button).remove();
+ alert(strings.nothing);
+ },
+ getauthors: function() {
+ if ( jQuery('div.wrap').length > 1 )
+ jQuery('div.wrap').gt(0).remove();
+ jQuery('div.wrap').empty().append('<h2>$authhead</h2><h3>' + this.title + '</h3>');
+ jQuery('div.wrap').append('<p id=\"auth\">$loadauth</p>');
+ jQuery('p#auth').load('index.php?import=blogger&noheader=true&authors=1',{blog:this.blog});
+ },
+ init: function() {
+ this.update();
+ var i = this.blog;
+ jQuery(this.button).bind('click', function(){return blogs[i].click();});
+ this.kicks = 0;
+ this.checks = 0;
+ },
+ click: function() {
+ if ( this.mode == 'init' || this.mode == 'stopped' || this.mode == 'posts' || this.mode == 'comments' ) {
+ this.mode = 'started';
+ this.start();
+ jQuery(this.button).attr('value', strings.stop);
+ } else if ( this.mode == 'started' ) {
+ return false; // let it run...
+ this.mode = 'stopped';
+ this.stop();
+ if ( this.checks > 0 || this.kicks > 0 ) {
+ this.mode = 'stopping';
+ jQuery(this.button).attr('value', strings.stopping);
+ } else {
+ jQuery(this.button).attr('value', strings.cont);
+ }
+ } else if ( this.mode == 'authors' ) {
+ document.location = 'index.php?import=blogger&authors=1&blog='+this.blog;
+ //this.mode = 'authors2';
+ //this.getauthors();
+ }
+ return false;
+ }
+ };
+ $init
+ jQuery.each(blogs, function(i, me){me.init();});
+ </script>\n";
+ }
+
+ // Handy function for stopping the script after a number of seconds.
+ function have_time() {
+ global $importer_started;
+ if ( time() - $importer_started > MAX_EXECUTION_TIME )
+ die('continue');
+ return true;
+ }
+
+ function get_total_results($type, $host) {
+ $headers = array(
+ "GET /feeds/$type/default?max-results=1&start-index=2 HTTP/1.0",
+ "Host: $host",
+ "Authorization: AuthSub token=\"$this->token\""
+ );
+ $request = join( "\r\n", $headers ) . "\r\n\r\n";
+ $sock = $this->_get_blogger_sock( $host );
+ if ( ! $sock ) return;
+ $response = $this->_txrx( $sock, $request );
+ $response = $this->parse_response( $response );
+ $parser = xml_parser_create();
+ xml_parse_into_struct($parser, $response['body'], $struct, $index);
+ xml_parser_free($parser);
+ $total_results = $struct[$index['OPENSEARCH:TOTALRESULTS'][0]]['value'];
+ return (int) $total_results;