PDA

View Full Version : Looking for a piece of code



Wojtek
February 4th, 2003, 11:25
My moreover news take forever to load, thus my site takes ages to load.

I've came up with a neat idea :)

I'll make a Cron Job that saves the output of a my code.
Kind of like process js code on the server and save it's output in a file.

This way I'll just have to load news.info file for exemple, instead of my user having to send 6 requests to moreover each time he enters my site.

Cron will be set up to run each hour so news are still upto date.

How can this be done?
I'd just need some bits and piece of code, I'll put it together myself.
Php or cgi, dosnt mather.

Thanks :)

spec
February 4th, 2003, 15:36
Please elaborate. I do not understand how moreover news works.

Wojtek
February 4th, 2003, 15:52
basically,

I need a script that acceses a page,
processes the javascript on it,
and saves the output in html-only

Wojtek
February 4th, 2003, 19:59
<table border="0" cellspacing="0" cellpadding="0" width="320">
<tr>
<td width="320"><p align="center"><script LANGUAGE="JavaScript">// the array global_article is used to allow multiple categories
var global_article = new Array()
var global_article_counter = 0
var article = null
var early_exit = 0
var moreover_text = 0;
// do not remove this function clone()
function load_wizard()
{
var newwin = window.open("","clone","resizable,scrollbars,width=500");
document.forms.moreover_clone.submit();
return true;
}
// end of do not remove this function clone()</script> <script
LANGUAGE="Javascript" SRC="http://p.moreover.com/cgi-local/page?index_topstories+js"></script>
<script LANGUAGE="JavaScript">// load global_article array with articles from cluster
if (article != null)
{
for (var article_counter = 0; article_counter < Math.min(7,article.length); article_counter++)
{
global_article[global_article_counter] = article[article_counter]
global_article[global_article_counter].url += "' TARGET='_blank"
global_article[global_article_counter].document_url += "' TARGET='_blank"
global_article_counter++
}
}
else
{
if (early_exit == 0)
{
document.writeln("<center>Please reload this page to view the headlines</center>")
early_exit = 1
}
}</script> <script LANGUAGE="JavaScript"> <!--
if (global_article.length == 0)
{
if (early_exit)
{
document.writeln("<CENTER>Please reload this page to view the headlines</CENTER>");
}
else
{
document.writeln("<CENTER>Sorry, no articles matched your search criteria</CENTER>");
early_exit = 1;
}
}
// --></script> <script
LANGUAGE="JavaScript">if (early_exit == 0)
{
var width = "320"
var category = ""
var numberofarticles = global_article.length
var item_spacing = "5"
var cluster_bgcolor = "ffffff"
var cluster_border = "0"
var heading_display = "Yes"
var time_display = "Yes"
var cell_spacing = "0"
var cell_padding = "3"
var heading_bgcolor
var heading_font
var heading_font_size
var heading_fgcolor
var headline_bgcolor
var headline_font
var headline_font_size
var headline_fgcolor
var source_font
var source_font_size
var source_fgcolor
var access_font
var access_font_size
var access_fgcolor
var time_font
var time_font_size
var time_fgcolor
var time = new Array(global_article.length)

// Print out the table containing the headlines
document.writeln("<CENTER><TABLE BORDER="+cluster_border+" BGCOLOR='#"+cluster_bgcolor+"' WIDTH='"+width+"' CELLPADDING=2 CELLSPACING=0>")
document.writeln("<tr><td align='center'><img src='http://i.moreover.com/images/moreover_wizard_link.gif' border='0'></td></tr>")
document.writeln("<TR><TD><CENTER><TABLE BGCOLOR='#"+cluster_bgcolor+"' CELLPADDING="+cell_padding+" CELLSPACING="+cell_spacing+" WIDTH='100%'>")

// Start loop for articles
for (var counter=0; counter < numberofarticles; counter++)
{
// Reset formatting settings to original values
heading_bgcolor = "ffffff"
heading_font = "Arial,Helvetica, sans-serif"
heading_font_size = "-1"
heading_fgcolor = "800000"
headline_bgcolor = "ffffff"
headline_font = "Arial,Helvetica, sans-serif"
headline_font_size = "-1"
headline_fgcolor = "000000"
source_font = "Arial,Helvetica, sans-serif"
source_font_size = "-2"
source_fgcolor = "000080"
access_font = "Arial,Helvetica, sans-serif"
access_font_size = "-2"
access_fgcolor = "000080"
time_font = "Arial,Helvetica, sans-serif"
time_font_size = "-2"
time_fgcolor = "000080"

if ((counter == (global_article.length - 1)) && moreover_text == 1)
{
headline_fgcolor = source_fgcolor;
time_display = "No";
}

// Check for new category
if ((category != global_article[counter].cluster) && (heading_display == "Yes"))
{
// Set current category to new category
category = global_article[counter].cluster

// Print a new category heading
// document.writeln("<TR BGCOLOR='#"+heading_bgcolor+"'><TD>")
// document.writeln("<FONT SIZE="+heading_font_size+" FACE="+heading_font+" COLOR='#"+heading_fgcolor+"'>")
// document.writeln("<B>"+global_article[counter].cluster+"</B></FONT></TD></TR>")
}

// Print out the headline
document.writeln("<TR BGCOLOR='#"+headline_bgcolor+"'><TD><A HREF='"+global_article[counter].url+"' >")
document.writeln("<FONT SIZE="+headline_font_size+" FACE="+headline_font+" COLOR='#"+headline_fgcolor+"'")
document.writeln(">"+global_article[counter].headline_text+"...</FONT></A><br>")


// Print out the source
if ((counter != (global_article.length - 1)) || moreover_text != 1)
{
document.writeln("<A HREF='"+global_article[counter].document_url+"' >")
document.writeln("<FONT FACE="+source_font+" SIZE="+source_font_size+" COLOR='#"+source_fgcolor+"'>")
document.writeln(""+global_article[counter].source+"</FONT></A>&nbsp;&nbsp;")
}


// Print out reg/sub if appropriate
if (global_article[counter].access_status == "sub" || global_article[counter].access_status == "reg")
{
document.writeln(" <A HREF='"+global_article[counter].access_registration+"'>")
document.writeln("<FONT FACE="+access_font+" SIZE="+access_font_size)
document.writeln(" COLOR='#"+access_fgcolor+"'>"+global_article[counter].access_status+"</FONT></A>&nbsp;&nbsp;")
}

// Print out the harvest time
if (time_display == "Yes")
{
// Make a new date object
time[counter] = new Date(global_article[counter].harvest_time)
time[counter].setHours(time[counter].getHours() - (time[counter].getTimezoneOffset() / 60 )) // adjust the time to local
document.writeln("<FONT FACE="+time_font+" SIZE="+time_font_size+" COLOR='#"+time_fgcolor+"'>")
document.writeln(""+time[counter].toString()+"</FONT>")
}

document.writeln("</TD></TR><TR BGCOLOR='#"+headline_bgcolor+"'><TD BGCOLOR='#"+headline_bgcolor+"' HEIGHT="+item_spacing+"></TD></TR>")
} // End of article loop

// Start of clone button code //
// Note: Do not remove any of the code in this section //
document.writeln("<TR><FORM METHOD='POST' ACTION='http://w.moreover.com/cgi-local/wizard_clone.pl' target='clone' name='moreover_clone'><TD align='center'>")
document.writeln("<INPUT TYPE='hidden' NAME='heading_font_size' VALUE='-1'><INPUT TYPE='hidden' NAME='source_font_size' VALUE='-2'>")
document.writeln("<INPUT TYPE='hidden' NAME='cluster_width' VALUE='400'><INPUT TYPE='hidden' NAME='time_display' VALUE='Yes'>")
document.writeln("<INPUT TYPE='hidden' NAME='time_font' VALUE='Arial,Helvetica, sans-serif'><INPUT TYPE='hidden' NAME='cluster_cellspacing' VALUE='0'>")
document.writeln("<INPUT TYPE='hidden' NAME='heading_font' VALUE='Arial,Helvetica, sans-serif'><INPUT TYPE='hidden' NAME='number_of_headlines' VALUE='11'>")
document.writeln("<INPUT TYPE='hidden' NAME='cluster_bgcolor' VALUE='ffffff'><INPUT TYPE='hidden' NAME='time_fgcolor' VALUE='000080'>")
document.writeln("<INPUT TYPE='hidden' NAME='access_fgcolor' VALUE='000080'><INPUT TYPE='hidden' NAME='time_font_size' VALUE='-2'>")
document.writeln("<INPUT TYPE='hidden' NAME='headline_bgcolor' VALUE='ffffff'><INPUT TYPE='hidden' NAME='cluster_name' VALUE='index_topstories'>")
document.writeln("<INPUT TYPE='hidden' NAME='access_font_size' VALUE='-2'><INPUT TYPE='hidden' NAME='heading_display' VALUE='Yes'>")
document.writeln("<INPUT TYPE='hidden' NAME='headline_fgcolor' VALUE='000000'><INPUT TYPE='hidden' NAME='source_font' VALUE='Arial,Helvetica, sans-serif'>")
document.writeln("<INPUT TYPE='hidden' NAME='access_font' VALUE='Arial,Helvetica, sans-serif'><INPUT TYPE='hidden' NAME='headline_font_size' VALUE='-1'>")
document.writeln("<INPUT TYPE='hidden' NAME='headline_font' VALUE='Arial,Helvetica, sans-serif'><INPUT TYPE='hidden' NAME='heading_bold' VALUE='Yes'>")
document.writeln("<INPUT TYPE='hidden' NAME='item_spacing' VALUE='5'><INPUT TYPE='hidden' NAME='wizard_brand' VALUE='moreover'>")
document.writeln("<INPUT TYPE='hidden' NAME='heading_bgcolor' VALUE='ffffff'><INPUT TYPE='hidden' NAME='cluster_cellpadding' VALUE='1'>")
document.writeln("<INPUT TYPE='hidden' NAME='heading_fgcolor' VALUE='000000'><INPUT TYPE='hidden' NAME='source_fgcolor' VALUE='000080'>")
document.writeln("<INPUT TYPE='hidden' NAME='cluster_border' VALUE='0'><INPUT TYPE='hidden' NAME='cluster_layout' VALUE='<br>'>")

document.writeln("</TD></FORM></TR>")

// End of clone button code //

document.writeln("</TABLE></CENTER></TD></TR></TABLE></CENTER>")

// ************************************************************ ************************
// This code is subject to the copyright and warranty restrictions detailed at
// http://w.moreover.com/wizard_copyright.html
// Copyright 1999 Moreover.com Inc. All rights reserved.
// ************************************************************ *************************
}</script></td>
</tr>
</table>


This is the code with the javascript in it.
I need to transform it server-side so it puts the result of the javascript and not save it with the js code.

spec
February 5th, 2003, 02:45
I honostly do not think you can convert clientside output to server side as it is translated by the browser

Wojtek
February 5th, 2003, 07:48
Originally posted by spec
I honostly do not think you can convert clientside output to server side as it is translated by the browser
Are you sure there is nothing I can do?

This code takes forever to load on 56k due to the fact that the browser conects 7 times to the moreover server to retrieve the news.

I wanted to run some cron script that would access it 7 times per hour and write it into html so I could just include the html with SSI.

Would be ALOT faster.

Nothing can be done here? :(

Wojtek
February 5th, 2003, 07:58
Well,

Yesterday I found a cgi script with does what I need to do:
Connects to the server and retirebes the news.

Only problem is that it wont run properly.
I keep getting an "Premature end of script headers" error in my error log along with a 500 error via browser.

What could be the problem?