Jump to content


PHP help


5 replies to this topic

#1 DoctorPhotoshop

    Young Padawan

  • Members
  • Pip
  • 67 posts

Posted 27 May 2006 - 11:59 AM

Hey, I'm having trouble fixing this...

http://pixelgroovy.c...all&category=35

<?

include('config.php');
/*
include(mnminclude.'html1.php');
*/
include(mnminclude.'link.php');
	
if(!empty($_REQUEST['rows'])) {
	$rows = intval($_REQUEST['rows']);
	if ($rows > 100) $rows = 30; //avoid abuses
} else $rows = 30;
	
$if_modified = get_if_modified();

if(!empty($_REQUEST['time'])) {
	// Prepare for times
	if(!($time = check_integer('time')))
		die;
	$sql = "SELECT link_id, count(*) as votes FROM votes, links WHERE  ";	
	if ($time > 0) {
		$from = time()-$time;
		$sql .= "vote_date > FROM_UNIXTIME($from) AND ";
	}
	$sql .= "vote_link_id=link_id  AND link_status != 'discard' GROUP BY vote_link_id  ORDER BY votes DESC LIMIT $rows";
	$last_modified = time();
	$title = _('Pixel Groovy: more grooves in') . ' ' . txt_time_diff($from);
	//$link_date = "modified";
	$link_date = "";
} else {
	// All the others
	$search = get_search_clause('boolean');
	// The link_status to search
	if(!empty($_REQUEST['status'])) {
		$status = $db->escape(preg_replace('/ /', '', trim($_REQUEST['status'])));
	} else {
		// By default it searches on all
		if($search) $status = 'all';
		else $status = 'published';
	}
	/*****  WARNING
		this function is to redirect to feed burner
		comment it out
		You have been warned 

	if (!$search && empty($_REQUEST['category'])) {
		check_redirect_to_feedburner($status);
	}
	
	 END WARNING ******/
	
	
	switch ($status) {
		case 'published':
			$order_field = 'link_published_date';
			$link_date = 'published_date';
			$title = _('Pixel Groovy: front page');
			break;
		case 'queued':
			$title = _('Pixel Groovy: in query');
			$order_field = 'link_date';
			$link_date = "date";
			$home = "/shakeit.php";
			break;
		case 'all':
			$title = _('Pixel Groovy: all');
			$order_field = 'link_date';
			$link_date = "date";
			break;
	}
	
	
	if($status == 'all') {
		$from_where = "FROM links WHERE link_status!='discard' ";
	} else {
		$from_where = "FROM links WHERE link_status='$status' ";
	}
	if(($cat=check_integer('category'))) {
		$from_where .= " AND link_category=$cat ";
		$category_name = $db->get_var("SELECT category_name FROM categories WHERE category_id = $cat AND category_lang='$dblang'");
		$title .= " -$category_name-";
	}
	
	if($search) {
		$from_where .= "AND $search";
		$title = _('Pixel Groovy') . ": " . htmlspecialchars(strip_tags($_REQUEST['search']));
	}
	
	$order_by = " ORDER BY $order_field DESC ";
	$last_modified = $db->get_var("SELECT UNIX_TIMESTAMP(max($order_field)) links $from_where");
	if ($if_modified > 0) {
		$from_where .= " AND $order_field > FROM_UNIXTIME($if_modified)";
	}
	$sql = "SELECT link_id $from_where $order_by LIMIT $rows";
}

if ($last_modified <= $if_modified) {
	header('HTTP/1.1 304 Not Modified');
	exit();
}



do_header($title);

$link = new Link;
$links = $db->get_col($sql);
if ($links) {
	foreach($links as $link_id) {
		$link->id=$link_id;
		$link->read();
		$category_name = $db->get_var("SELECT category_name FROM categories WHERE category_id = $link->category AND category_lang='$dblang'");
		$content = text_to_html($link->content);
		echo "	<item>\n";
		echo "		<title><![CDATA[$link->title]]></title>\n";
		echo "		<link>".get_permalink($link->id)."</link>\n";
		echo "		<comments>".get_permalink($link->id)."</comments>\n";
		if (!empty($link_date))
			echo "		<pubDate>".date("r", $link->$link_date)."</pubDate>\n";
		else echo "	  <pubDate>".date("r", time())."</pubDate>\n";
		echo "		<dc:creator>$link->username</dc:creator>\n";
		echo "		<category>$category_name</category>\n";
		echo "		<guid>".get_permalink($link->id)."</guid>\n";
		echo "		<description><![CDATA[$content";
		//echo " » <a href='".htmlspecialchars($link->url)."'>"._('tutorial original')."</a>";
		echo "]]></description>\n";
		// echo "		<trackback:ping>".get_trackback($link->id)."</trackback:ping>\n";  // no standard
		//echo "<content:encoded><![CDATA[ ]]></content:encoded>\n";
		echo "	</item>\n\n";
	}
}

do_footer();

function do_header($title) {
	global $last_modified, $dblang, $home;

	header('Last-Modified: ' .  gmdate('D, d M Y H:i:s', $last_modified) . ' GMT');
	header('Content-type: text/xml; charset=UTF-8', true);
	echo '<?xml version="1.0" encoding="UTF-8"?'.'>' . "\n";
	echo '<rss version="2.0" '."\n";
	echo '	 xmlns:content="http://purl.org/rss/1.0/modules/content/"'."\n";
	echo '	 xmlns:wfw="http://wellformedweb.org/CommentAPI/"'."\n";
	echo '	 xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
	echo ' >'. "\n";
	echo '<channel>'."\n";
	echo'	<title>'.$title.'</title>'."\n";
	echo'	<link>http://'.get_server_name().$home.'</link>'."\n";
	echo"	<image><title>".get_server_name()."</title><link>http://".get_server_name()."</link><url>http://".get_server_name()."/img/common/mnm-rss.gif</url></image>\n";
	echo'	<description>'._('Sitio colaborativo de publicación y comunicación entre blogs').'</description>'."\n";
	echo'	<pubDate>'.date("r", $last_modified).'</pubDate>'."\n";
	echo'	<generator>http://mnm.uib.es/gallir/pixelgroovy/</generator>'."\n";
	echo'	<language>'.$dblang.'</language>'."\n";
}

function do_footer() {
	echo "</channel>\n</rss>\n";
}

function get_if_modified() {
	// Bug in FeedBurner, it needs all items
	if (preg_match('/feedburner/i', $_SERVER['HTTP_USER_AGENT'])) return 0;
	//

	// Get client headers - Apache only 
	$request = apache_request_headers(); 
	if (isset($request['If-Modified-Since'])) { 
		  // Split the If-Modified-Since (Netscape < v6 gets this wrong) 
		$modifiedSince = explode(';', $request['If-Modified-Since']); 
		return strtotime($modifiedSince[0]); 
	} else { 
		return 0;
	}
}

function check_redirect_to_feedburner($status) {
	global $globals; 

	if (!$globals['redirect_feedburner'] || preg_match('/feedburner/', $_SERVER['PHP_SELF']) || preg_match('/feedburner/i', $_SERVER['HTTP_USER_AGENT'])) return;

	switch ($status) {
		case 'published':
			header("Location: [url=http://feeds.feedburner.com/pixelgroovy/published");]http://feeds.feedburner.com/pixelgroovy/published");[/url]
			exit();
			break;
		/****
			FeedBurner is not enough fast updating it
		case 'queued':
			header("Location: [url=http://feeds.feedburner.com/meneame/queued");]http://feeds.feedburner.com/meneame/queued");[/url]
			exit();
			break;
		****/
		case 'all':
			header("Location: [url=http://feeds.feedburner.com/pixelgroovy/all");]http://feeds.feedburner.com/pixelgroovy/all");[/url]
			exit();
			break;
	}
	
}
?>

Edited by DoctorPhotoshop, 27 May 2006 - 01:58 PM.


#2 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 27 May 2006 - 12:18 PM

PLEASE wrap code in code tags. :D :D

Anywho...

The error produced on that site is puzzling because apache_request_headers is a inbuilt function therefore cant be missing.

I did a bit of quick research on this and the manual page probally answears it: http://uk.php.net/ap...request_headers

Quote

This function is only supported when PHP is installed as an Apache module.

Its an apache specific function so you may want to check if your server is using apache or not :D

edit: it is

Edited by .Matt, 27 May 2006 - 12:21 PM.


#3 DoctorPhotoshop

    Young Padawan

  • Members
  • Pip
  • 67 posts

Posted 27 May 2006 - 01:56 PM

So what do i do?

#4 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 27 May 2006 - 02:12 PM

Apolagies i was not clear.

And i shant be much clearer....i do not know....

You could try changing

// Get client headers - Apache only
$request = apache_request_headers();

to

// Get client headers - Apache only
$request = getallheaders();

try that, if not, then i would say its a server configuration issue. I think your hosted with bluehost? check around their forums for any similar error with that function.

#5 DoctorPhotoshop

    Young Padawan

  • Members
  • Pip
  • 67 posts

Posted 27 May 2006 - 06:04 PM

Quote

The error is comming up because php is not setup as an apache module on our servers. We are running php in cgi mode for security and stability reasons. Unfortunatly that means that the function the feed is useing will not work.


Any help?

Edited by DoctorPhotoshop, 27 May 2006 - 06:32 PM.


#6 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 28 May 2006 - 05:26 AM

It appears to be working now so i can only assume you did something while i was asleep lol ;)

edit: yeah, for future ref he did what i suggested above :tiphat:

Edited by .Matt, 30 May 2006 - 01:28 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users