[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 12-16-2005, 09:33 AM   #1 (permalink)
NamePros Regular
 
Jim_Westergren's Avatar
 
Join Date: May 2005
Location: Cochabamba, Bolivia
Posts: 721
1,268.00 NP$ (Donate)

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 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
JimWestergren.com | Follow me on Twitter
Jim_Westergren is offline  
Old 12-16-2005, 09:47 AM   #2 (permalink)
mch
NamePros Regular
 
Join Date: Nov 2005
Location: EU
Posts: 248
99.25 NP$ (Donate)

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 05:18 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85