php tag ?

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
andre
Posts: 28
Joined: Sun 4. Apr 2004, 19:59

php tag ?

Post by andre »

hi,

this works:
http://andres.homelinux.net/myres/scrip ... s2html.php
the code:

Code: Select all

// file test_rss2html.php
<?php
include_once('ext_rss2html.php');
rss2html(0,2,'http://dwlt.net/tapestry/peanuts.rdf');
?>
the output:

Code: Select all

<div><a target="_blank" href="http://www.snoopy.com/comics/peanuts/archive/peanuts-20040624.html" >Peanuts for 24 Jun 2004</a><br /><div><img src="http://www.snoopy.com/comics/peanuts/archive/images/peanuts2004305050624.gif" border="0" /></div></div><br>
<div><a target="_blank" href="http://www.snoopy.com/comics/peanuts/archive/peanuts-20040623.html" >Peanuts for 23 Jun 2004</a><br /><div><img src="http://www.snoopy.com/comics/peanuts/archive/images/peanuts2004067340623.gif" border="0" /></div></div><br>
all swell so far, the 2 newest images are loaded. but now i try to embed this to my phpwcms site:
http://andres.homelinux.net/web/
the code (in html article):

Code: Select all

<center>
[PHP]
include_once('../myres/scripts/ext_rss2html.php');
rss2html(0,2,'http://dwlt.net/tapestry/peanuts.rdf');
[/PHP]
</center>
the output:

Code: Select all

<center>
<div><a target="_blank" href="" ></a><br /><div></div></div><br>
<div><a target="_blank" href="http://www.snoopy.com/comics/peanuts/archive/peanuts-20040623.html" >Peanuts for 23 Jun 2004</a><br /><div><img src="http://www.snoopy.com/comics/peanuts/archive/images/peanuts2004067340623.gif" border="0" /></div></div><br>

</center>
as you see the 1st image is not outputted to my site ?
can't find where the fault is, and i'm starting to go (pea)nuts :?

cheers
.andre

Code: Select all

<?php
// rss2html.php
$current_tag = '';
$parent_tag = '';
$item_count = 0;
$channel = array();
$image = array();
$item = array();
$textinput = array();
function my_run_xml_parser ($xml_file, $start_tag_function, $end_tag_function, $data_function) {
	$xp = xml_parser_create();
	xml_set_element_handler ($xp, $start_tag_function, $end_tag_function);
	xml_set_character_data_handler ($xp, $data_function);
	xml_parser_set_option ($xp, XML_OPTION_CASE_FOLDING, TRUE);
	xml_parser_set_option ($xp, XML_OPTION_SKIP_WHITE, TRUE);
	if (!($fp = fopen ($xml_file, "r"))) { die ("Could not read $xml_file"); }
		while ($xml = fread ($fp, 4096)) { if (!xml_parse ($xp, $xml, feof ($fp))) {
		die("XML parser error: " . xml_error_string (xml_get_error_code ($xp)));}
	}
	xml_parser_free ($xp);
}

function my_rss_tag_start ($parser, $tag_name, $attributes) {
	global $current_tag, $parent_tag;
	$tag_name = strtolower ($tag_name);
	$current_tag = $tag_name;
	if ($tag_name == 'channel' || $tag_name == 'item' || $tag_name == 'image' || $tag_name == 'textinput') {
		$parent_tag = $tag_name;
	}
}

function my_rss_tag_end ($parser, $tag_name) {
	global $current_tag, $parent_tag, $item_count;
	$tag_name = strtolower ($tag_name);
	$current_tag = '';
	if ($tag_name == 'channel' || $tag_name == 'item' || $tag_name == 'image' || $tag_name == 'textinput') {
		$parent_tag = '';
		if ($tag_name == 'item') {
			$item_count++;
		}
	}
}

function my_rss_character_data ($parser, $data) {
	global $current_tag, $parent_tag, $item, $channel, $image, $textinput, $item_count, $output;
	$data = trim (htmlspecialchars ($data));
	if ($current_tag == 'title' || $current_tag == 'link' || $current_tag == 'description' || $current_tag == 'url' || $current_tag == 'width' || $current_tag == 'height' || $current_tag == 'name' || $current_tag == 'guid' || $current_tag == 'content:encoded') {
		$current_tag = strtolower ($current_tag);
		if ($parent_tag == 'item') {
			$item[$item_count][$current_tag] .= $data;
		}
		else if ($parent_tag == 'channel') {
			$channel[$current_tag] .= $data;
		}
		else if ($parent_tag == 'image') {
			$image[$current_tag] .= $data;
		}
		else if ($parent_tag == 'textinput') {
			$textinput[$current_tag] .= $data;
		}
	}
}
function rss2html($top, $headers, $rss_uri){
global $current_tag,$parent_tag,$item_count,$channel,$image,$item,$textinput;
my_run_xml_parser ($rss_uri, 'my_rss_tag_start', 'my_rss_tag_end', 'my_rss_character_data');
if (!empty ($image)) {
	$channel_image = "<img border=\"0\" src=\"" . $image['url'] . "\" width=\"" . $image['width'] . "\" height=\"" . $image['height'] . "\" alt=\"" . $channel_title . " button\" title=\"" . $image['description'] . "\" class=\"floatl\" style=\"margin-right:5px;\" />";
}
$channel_title = $channel['title'];
$top_text = "<div><a target=\"_blank\" href=\"" . $channel['link'] . "\">" . $channel_image . $channel_title . "</a><br /><font>".$channel['description']."</font></div><br>";
if ($headers==0) $number_items = sizeof ($item);
else $number_items = $headers;
for ($i = 0; $i < $number_items; $i++) {
	$current_link = $item[$i]['guid'];
	if (!empty ($item[$i]['link'])) {
		$current_link = $item[$i]['link'];
	}
	$current_description = html_entity_decode ($item[$i]['description']);
	if (!empty ($item[$i]['content:encoded'])) {
		$current_description = $item[$i]['content:encoded'];
	}
	$cdata_test = strpos ($current_description, "<![CDATA["); 
	if ($cdata_test != 0) {
		$current_description = html_entity_decode ($current_description);
	}
	$item_title = $item[$i]['title'];
	$output .= "<div><a target=\"_blank\" href=\"" . $current_link . "\" " . $open_new_window . ">" . $item_title . "</a><br /><div>" . $current_description .  "</div></div><br>\n";
}
if (!empty ($textinput['link']) && !empty ($textinput['name'])) {
	if (empty ($textinput['title'])) {
		$textinput['title'] = 'Search';
	}
	$output .= "<h2>" . $textinput['title'] . "</h2>";
	$output .= "<form action=\"" . $textinput['link'] . "\" method=\"get\">\n<input type=\"text\" name=\"" . $textinput['name'] . "\" />\n<input type=\"submit\" value=\"Search\" />\n</form>\n";
}
if ($top==1) echo $top_text;
echo $output;
}
?>
User avatar
DeXXus
Posts: 2168
Joined: Fri 28. Nov 2003, 06:20
Location: USA - Florida

Post by DeXXus »

It works fine anywhere in the Template, so it looks like you gotta increase the $headers parameter by 1 because it's in a "content part" of an article...

This oughta produce the same effect (last two days) in a "content part":

Code: Select all

[PHP] 
include_once('../myres/scripts/ext_rss2html.php'); 
rss2html(0,3,'http://dwlt.net/tapestry/peanuts.rdf'); 
[/PHP] 
andre
Posts: 28
Joined: Sun 4. Apr 2004, 19:59

Post by andre »

nope!

the newest (24 jun 2004) is not shown in phpwcms, look the generated html source:

Code: Select all

<div><a target="_blank" href="" ></a><br /><div></div></div><br>
<div><a target="_blank" href="http://www.snoopy.com/comics/peanuts/archive/peanuts-20040623.html" >Peanuts for 23 Jun 2004</a><br /><div><img src="http://www.snoopy.com/comics/peanuts/archive/images/peanuts2004067340623.gif" border="0" /></div></div><br>

<div><a target="_blank" href="http://www.snoopy.com/comics/peanuts/archive/peanuts-20040622.html" >Peanuts for 22 Jun 2004</a><br /><div><img src="http://www.snoopy.com/comics/peanuts/archive/images/peanuts2061010040622.gif" border="0" /></div></div><br>

</center>
<br /><br /></td>
the first div is missing href and img ?!

as seen on my previous post when i use the script outside phpwcms the newest IS included:

Code: Select all

<div><a target="_blank" href="http://www.snoopy.com/comics/peanuts/archive/peanuts-20040624.html" >Peanuts for 24 Jun 2004</a><br /><div><img src="http://www.snoopy.com/comics/peanuts/archive/images/peanuts2004305050624.gif" border="0" /></div></div><br>
<div><a target="_blank" href="http://www.snoopy.com/comics/peanuts/archive/peanuts-20040623.html" >Peanuts for 23 Jun 2004</a><br /><div><img src="http://www.snoopy.com/comics/peanuts/archive/images/peanuts2004067340623.gif" border="0" /></div></div><br>
<div><a target="_blank" href="http://www.snoopy.com/comics/peanuts/archive/peanuts-20040622.html" >Peanuts for 22 Jun 2004</a><br /><div><img src="http://www.snoopy.com/comics/peanuts/archive/images/peanuts2061010040622.gif" border="0" /></div></div><br>
ps. i'm using phpwcms Release 1.1-RC4 08-06-2004
User avatar
Oliver Georgi
Site Admin
Posts: 9900
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

it's not possible to declare functions in function (as far as I know) - so you need to include your functions outside the [PHP][/PHP] tag.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
User avatar
DeXXus
Posts: 2168
Joined: Fri 28. Nov 2003, 06:20
Location: USA - Florida

Post by DeXXus »

andre wrote:nope!
Hmm, well it's working for me as I described. I put the "rss2html.php" file in phpWCMS "root", pasted the following into a content part "plain text", and it generates 2 cartoons Peanuts for 23 Jun 2004 & Peanuts for 22 Jun 2004. 8)

Code: Select all

[PHP]include_once ('ext_rss2html.php');
rss2html(0,3,'http://dwlt.net/tapestry/peanuts.rdf');
[/PHP]
Notice the "3" instead of "2" here:
Last edited by DeXXus on Thu 24. Jun 2004, 15:58, edited 1 time in total.
andre
Posts: 28
Joined: Sun 4. Apr 2004, 19:59

Post by andre »

hi oliver,
Oliver Georgi wrote:it's not possible to declare functions in function (as far as I know)
hmm...

Code: Select all

<?php
function foo()
{
  function bar()
  {
   echo "I don't exist until foo() is called.\n";
  }
}

/* We can't call bar() yet
   since it doesn't exist. */

foo();

/* Now we can call bar(),
   foo()'s processesing has
   made it accessible. */

bar();

?> 
or do you mean "declare" (i've newer used this) : http://de.php.net/manual/en/control-str ... eclare.php
Oliver Georgi wrote:so you need to include your functions outside the [PHP][/PHP] tag.
how do i do that ? "<?php ... ?>" doesnt seem to work... or is there a php content type or something?

and one thing that i don't understand is why only the first href and img is not "echoed" but the rest works ok....

thnx for ya help
.andre
ps. in "worst" case i could do a class or use url variables...
andre
Posts: 28
Joined: Sun 4. Apr 2004, 19:59

Post by andre »

DeXXus wrote:
andre wrote:nope!
Hmm, well it's working for me as I described. I put the "rss2html.php" file in phpWCMS "root", pasted the following into a content part "plain text", and it generates 2 cartoons Peanuts for 23 Jun 2004 & Peanuts for 22 Jun 2004. 8)

Code: Select all

[PHP]include_once ('ext_rss2html.php');
rss2html(0,3,'http://dwlt.net/tapestry/peanuts.rdf');
[/PHP]
read my posts again ! the NEWEST is from 24 Jun 2004 and it is NOT generated... (and it should generate 3 cartoons not 2)

look here: http://andres.homelinux.net/myres/scrip ... s2html.php
User avatar
Oliver Georgi
Site Admin
Posts: 9900
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

Problem is that there are functions included in your external PHP. I do not recommend this.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
andre
Posts: 28
Joined: Sun 4. Apr 2004, 19:59

Post by andre »

ok,

i didn't notice that there's a content type EXT. CONTENT !
so i converted my script for usage with URL variables and used it in the EXT. CONTENT and voila: http://andres.homelinux.net/web/ the newest cartoon is rendered 8)

cheers
.andre
colech
Posts: 178
Joined: Thu 25. Mar 2004, 01:01
Location: Washington, USA
Contact:

Post by colech »

andre wrote:ok,

i didn't notice that there's a content type EXT. CONTENT !
so i converted my script for usage with URL variables and used it in the EXT. CONTENT and voila: http://andres.homelinux.net/web/ the newest cartoon is rendered 8)

cheers
.andre
I am trying to use the type "ext. content" right now and would like to know the proper method to get files to show up in the list of available files in the content/pages directory? Can I manually copy files to that directory or do I HAVE to use the ftp upload in the phpWCMS backend? I want to know because I would like to be able to modify a file in content/pages in Dreamweaver and have the changes be immediately reflected in the content part without having to cut and paste the html or upload the file again through the backend ftp upload. I hope this makes sense to someone...

Here's a link to my original question.
while !sleeping {
work_on(phpwcms);
}
// Check out our web development company!
// "Your business has character... don't hide it!"
User avatar
Oliver Georgi
Site Admin
Posts: 9900
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

Copy manually - also complete directories/subdirs are possible there.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
colech
Posts: 178
Joined: Thu 25. Mar 2004, 01:01
Location: Washington, USA
Contact:

Post by colech »

Thankyou Oliver!

Now... why do only 2 (one html and one php file extension) of the 6 files (all html and php file extensions) I placed in the content/pages/ directory show us as options to select in the "ext. content" content part?
while !sleeping {
work_on(phpwcms);
}
// Check out our web development company!
// "Your business has character... don't hide it!"
User avatar
Oliver Georgi
Site Admin
Posts: 9900
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

don't know - these are the possible file extensions:
html htm txt php inc tmpl (upper and lower)

Maybe wrong permissions - check that each file is chmod-ed 644

Oliver
Last edited by Oliver Georgi on Mon 20. Dec 2004, 22:28, edited 1 time in total.
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
colech
Posts: 178
Joined: Thu 25. Mar 2004, 01:01
Location: Washington, USA
Contact:

Post by colech »

I'm actually using Win XP for this implementation. I have moved them in and out of the directory several times hoping that there was some cache somewhere I didn't know about that would be refreshed. I have logged in and out of phpWCMS backend. I have rebooted my OS, and I am wondering if there is a limitation on the number of files listed somewhere in a config file or something?
while !sleeping {
work_on(phpwcms);
}
// Check out our web development company!
// "Your business has character... don't hide it!"
User avatar
Oliver Georgi
Site Admin
Posts: 9900
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

no there is no limitation. I checked again on Win XP too - no problem - everything is listed.

Please send a screenshot if possible.

Image


Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
Post Reply