|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
syndication of articles
Greetings,
i am using a phpnuke script and as you might be knowing it has a builtin backend.php file thru which others can syndicate our articles. but i wanted something where even a html based site could syndicate our articles something like your site is providing. any suggestion and help in how to go ahead with that is appreciated. thanx |
|
#2
|
|||
|
|||
|
Hi,
Well it's a really simple process. First, you create a PHP script on your server that outputs only JavaScript commands. For example, to output the text "hello", you would use a PHP script like this <?php // Start the output ?> document.write("hello"); <?php // End output ?> Obviously you would loop through the articles on your server and use the JavaScript document.write funciton to output a whole bunch of document.write lines to form HTML tables, etc. Make sure you escape ' with \' and " with \". Once you've done the PHP script that outputs JavaScript, let the client call it like this: <script language="JavaScript" src="http://www.yoursite.com/feed.php"></script> that's really all there is to it. If you need any help, just reply to this post. |
|
#3
|
|||
|
|||
|
Hi mitch,
i am clueless as what u meant in the earlier post..anyway i am pasting the backend.php file.. ------------------------------- <?php /************************************************** **********************/ /* PHP-NUKE: Web Portal System */ /* =========================== */ /* */ /* Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve) */ /* http://phpnuke.org */ /* */ /* This program is free software. You can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License. */ /************************************************** **********************/ include("extention.inc"); include("mainfile.$phpEx"); header("Content-Type: text/plain"); $result = mysql_query("SELECT sid, title, time FROM ".$mpnTables['stories']." ORDER BY sid DESC limit 10"); if (!result) { echo "An error occured"; } else { echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"; echo "<!DOCTYPE rss PUBLIC \"-//Netscape Communications//DTD RSS 0.91//EN\"\n"; echo " \"http://my.netscape.com/publish/formats/rss-0.91.dtd\">\n\n"; echo "<rss version=\"0.91\">\n\n"; echo " <channel>\n"; echo " <title>$sitename</title>\n"; echo " <link>$nuke_url</link>\n"; echo " <description>$backend_title</description>\n"; echo " <language>$backend_language</language>\n\n"; echo " <image>\n"; echo " <title>$sitename</title>\n"; echo " <url>$backend_image</url>\n"; echo " <link>$nuke_url</link>\n"; echo " <description>$slogan</description>\n"; echo " <width>$backend_width</width>\n"; echo " <height>$backend_height</height>\n"; echo " </image>\n\n"; for ($m=0; $m < mysql_num_rows($result); $m++) { list($sid, $title, $time) = mysql_fetch_row($result); echo " <item>\n"; echo " <title>$title</title>\n"; echo " <link>$nuke_url/article.$phpEx?sid=$sid</link>\n"; echo " </item>\n\n"; } echo " </channel>\n\n"; echo "</rss>"; } ?> ------------------------------------------- other phpnuke sites can syndicate our articles by adding site.com/backend.php in their headline box.( an option in phpnuke) Now what i wanted is something as easy as your javascript code. where others could syndicate with those lovely tabled formatting pls guide me as how to do that. also will the syndicated articles change as we add new articles to our sites? thanx for your time |
|
#4
|
|||
|
|||
|
Well I guess the best way to learn something is to see how it works, so here's the code for our content feed:
<?php $result = mysql_query("select id, title from articles order by id desc limit 10"); ?> document.write('<a href="http://www.devarticles.com">'); document.write('<img border="0" src="http://www.devarticles.com/logo_small.gif">'); document.write('</a>'); document.write('<table border="1" bordercolor="#FF7300" width="150" cellspacing="0" cellpadding="0">'); document.write('<tr>'); document.write('<td bgcolor="#FF7300" height="21">'); document.write('<p style="margin-left:5">'); document.write('<font face="verdana" size="1" color="white">'); document.write('<b>Recent Articles</b>'); document.write('</font>'); document.write('</td>'); document.write('</tr>'); <?php while($row = mysql_fetch_array($result)) { $title = $row["title"]; $url = "http://www.devarticles.com/art/1/" . $row["id"]; ?> document.write('<tr>'); document.write('<td bgcolor="#FFEFCE" onMouseOver="this.style.backgroundColor=\'#FFFFC0\'" onMouseOut="this.style.backgroundColor=\'#FFEFCE\'">'); document.write('<p style="margin-top:5; margin-bottom:5; margin-left:10; margin-right:10">'); document.write('<a target="_blank" href="<?php echo $url; ?>">'); document.write('<font face="verdana" color="black" size="1">'); document.write('<?php echo str_replace("'", "\'", $title); ?>'); document.write('</font>'); document.write('</a>'); document.write('</td>'); document.write('</tr>'); <?php } echo "document.write('</table>');"; ?> Of course there is database connection code and I have renamed the tables, etc but that's our code! Call the file above something like myfeed.php. Now, to call it from any client: <script language="JavaScript" src="http://www.yoursite.com/myfeed.php"></script> Obviously you'll need to create an articles table with a title and id field, as well as the MySQL connect code in the script above, etc, but that shouldn't be too hard to follow... |
|
#5
|
|||
|
|||
|
Just an idea, you could use iframes?? just load the content page in the frame. i dont know if this would be faster or not tho?
|
|
#6
|
|||
|
|||
|
well this is the table structure..
# # Table structure for table `mpn_stories` # CREATE TABLE mpn_stories ( sid int(11) NOT NULL auto_increment, catid int(11) NOT NULL default '0', aid varchar(30) NOT NULL default '', title varchar(80) default NULL, time datetime default NULL, hometext text, bodytext text NOT NULL, comments int(11) default '0', counter mediumint(8) unsigned default NULL, topic int(3) NOT NULL default '1', informant varchar(20) NOT NULL default '', notes text NOT NULL, ihome int(1) NOT NULL default '0', PRIMARY KEY (sid), KEY idxstoriessiddesccatid (sid,catid), KEY idxstoriessiddesc (sid), KEY idxstoriessiddesctopic (sid,topic), KEY idxstoriessiddescihomecatid (sid,ihome,catid), KEY idxstoriestime (time), KEY idxstoriescounterdesctopic (counter,topic), KEY idxstoriescounterdesctime (counter,time), KEY idxstoriescatid (catid), KEY idxstoriesiddescinformant (sid,informant), KEY idxstoriesaid (aid), KEY idxstoriestopic (topic), KEY idxstoriescounterdesc (counter), KEY idxstoriescommentsdesc (comments) ) TYPE=MyISAM; |
|
#7
|
|||
|
|||
|
and this is the feed.php file
<?php header("Content-Type: text/javascript"); $db_server = "localhost"; $db_db = "mynuke"; $db_user = "fakeuser"; $db_pass = "fakepassword"; @$sConn = mysql_connect($db_server, $db_user, $db_pass); @$dConn = mysql_select_db($db_db, $sConn); if(!$sConn || !$dConn) { ?> document.write("Couldn't load news"); <?php } ?> $nResult = mysql_query("SELECT sid, title, time FROM ".$mpnTables['stories']." ORDER BY sid DESC limit 10"); ?> document.write('<a href="http://www.site.com">'); document.write('<img border="0" src="http://www.site.com/logo_small.gif">'); document.write('</a>'); document.write('<table border="1" bordercolor="#FF7300" width="150" cellspacing="0" cellpadding="0">'); document.write('<tr>'); document.write('<td bgcolor="#FF7300" height="21">'); document.write('<p style="margin-left:5">'); document.write('<font face="verdana" size="1" color="white">'); document.write('<b>Recent Articles</b>'); document.write('</font>'); document.write('</td>'); document.write('</tr>'); <?php while($row = mysql_fetch_array($nResult)) { $title = $row["title"]; $url = "http://localhost/mynuke/article.php?" . $row["sid"]; ?> document.write('<tr>'); document.write('<td bgcolor="#FFEFCE" onMouseOver="this.style.backgroundColor='#FFFFC0'" onMouseOut="this.style.backgroundColor='#FFEFCE'">'); document.write('<p style="margin-top:5; margin-bottom:5; margin-left:10; margin-right:10">'); document.write('<a target="_blank" href="<?php echo $url; ?>">'); document.write('<font face="verdana" color="black" size="1">'); document.write('<?php echo str_replace("'", "'", $title); ?>'); document.write('</font>'); document.write('</a>'); document.write('</td>'); document.write('</tr>'); <?php } echo "document.write('</table>');"; ?> |
|
#8
|
|||
|
|||
|
first, thanx to both of you for helping me out and secondly sorry for posting in installments, this thing never allowed me to post at one full time
anyway those are the above two files which i have and it is not working pls lemme know where i have gone wrong. and any suggestion is appreciated. it is very important to me .. thanx in advance again.. Mitch are you listening. help me out , also PabstER |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > syndication of articles |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|