NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP include of script inside smarty template file

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 12-16-2005, 10:33 AM THREAD STARTER               #1 (permalink)
NamePros Regular
 
Jim_Westergren's Avatar
Join Date: May 2005
Location: Sweden
Posts: 730
Jim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to behold
 




PHP include of script inside smarty template file


I need help!

Been trying for hours and also by googling and asking other people but don't get this shit to work.

I have a php script that displays a feed from my blog. An example can be seen on netmarketing.us

I want to set this up on my directories. My directories use the phplinkdirectory script which is done in smarty.

If I try this in the template file:

{php}include('rss.php');{/php}

Nothing gets output as HTML. There is nothing in the source code at all.

If I add this to the index.php:

include('rss.php');
$tpl->assign('RSS', $RSS);


And then use {$RSS} in the template file what happens is that it works but the feed gets displayed on the top of the file before all other HTML code and not where I want it.

I really need some help on this and can pay if needed. The only solution I could think of is to use iframes that calls a php file and on that file I can run the script, but iframes are not good SEO wise ...

The rss.php looks like this:

Code:
<?php

/*
Created by Global Syndication's RSS Parser
http://www.globalsyndication.com/rss-parser
*/

set_time_limit(0);

#### Here is the feed URL:

$file = "http://www.jimwestergren.com/category/online-marketing/feed/";

$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;

function startElement($parser, $name, $attrs) {
   	global $rss_channel, $currently_writing, $main;
   	switch($name) {
   		case "RSS":
   		case "RDF:RDF":
   		case "ITEMS":
   			$currently_writing = "";
   			break;
   		case "CHANNEL":
   			$main = "CHANNEL";
   			break;
   		case "IMAGE":
   			$main = "IMAGE";
   			$rss_channel["IMAGE"] = array();
   			break;
   		case "ITEM":
   			$main = "ITEMS";
   			break;
   		default:
   			$currently_writing = $name;
   			break;
   	}
}

function endElement($parser, $name) {
   	global $rss_channel, $currently_writing, $item_counter;
   	$currently_writing = "";
   	if ($name == "ITEM") {
   		$item_counter++;
   	}
}

function characterData($parser, $data) {
	global $rss_channel, $currently_writing, $main, $item_counter;
	if ($currently_writing != "") {
		switch($main) {
			case "CHANNEL":
				if (isset($rss_channel[$currently_writing])) {
					$rss_channel[$currently_writing] .= $data;
				} else {
					$rss_channel[$currently_writing] = $data;
				}
				break;
			case "IMAGE":
				if (isset($rss_channel[$main][$currently_writing])) {
					$rss_channel[$main][$currently_writing] .= $data;
				} else {
					$rss_channel[$main][$currently_writing] = $data;
				}
				break;
			case "ITEMS":
				if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
					$rss_channel[$main][$item_counter][$currently_writing] .= $data;
				} else {
					$rss_channel[$main][$item_counter][$currently_writing] = $data;
				}
				break;
		}
	}
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
	die("could not open XML input");
}

while ($data = fread($fp, 4096)) {
	if (!xml_parse($xml_parser, $data, feof($fp))) {
		die(sprintf("XML error: %s at line %d",
					xml_error_string(xml_get_error_code($xml_parser)),
					xml_get_current_line_number($xml_parser)));
	}
}
xml_parser_free($xml_parser);

// output HTML

### NOT NEEDED ####  print ("<div class=\"channelname\">" . $rss_channel["TITLE"] . "</div>"); 

if (isset($rss_channel["ITEMS"])) {
	if (count($rss_channel["ITEMS"]) > 0) {
# SIFFRAN NUMMER 5 NEDAN ANGER HUR MÅNGA SKA VISAS
		for($i = 0;$i < 5;$i++)  {
			if (isset($rss_channel["ITEMS"][$i]["LINK"])) {
			print ("\n<div class=\"itemtitle\"><a href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a></div>");
			} else {
			print ("\n<div class=\"itemtitle\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</div>");
			}
			 print ("<div class=\"itemdescription\">" . $rss_channel["ITEMS"][$i]["DESCRIPTION"] . "</div><br />"); 		}
	} else {
		print ("<b>There are no articles in this feed.</b>");
	}
}

?>
__________________
Jim Westergren
www.JimWestergren.com / Free website with N.nu
Jim_Westergren is offline  
Old 12-16-2005, 10:47 AM   #2 (permalink)
mch
NamePros Regular
Join Date: Nov 2005
Location: EU
Posts: 248
mch is on a distinguished road
 



My first guess is that maybe the RSS content gets to the output even before the <html> and that's why it is displayed on the top. I need to see the actual smarty template, the php script to say something useful.
mch is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
SendScript V1 . Great File Sending Script!! naqiboy Scripts For Sale 0 08-28-2005 01:58 PM
PHP Include Shop GHOwner For Sale / Advertising Board 0 10-18-2004 06:13 PM
Domain Rating Script for Sale : $200.00 - only 10 scripts will be sold fonzerelli_79 Scripts For Sale 3 08-31-2003 09:41 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 11:07 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger