Arrays/DB Inserts

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
briggs_ca
Forum Newbie
Posts: 1
Joined: Mon Aug 20, 2007 2:30 pm

Arrays/DB Inserts

Post by briggs_ca »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello,

Bare with me, I need to expain my environment before the php part!

I am using a plugin for a blogging/CMS system. 

It reads an RSS feed and then inserts specific fields (description, title, date, etc) into a database.

The problem with this is that I am reading 4 different RSS feeds from different websites, and they all haev different publish dates for their entries. Some of them have the specific time that the entry was made, others seem to attach the same date to all entries within a 12 hour build of the feed. (eg, 10 entries all with the time of 6:00, even though none of them were actually made at that time, just within that 12 hour period).

The plugin has two parts, the actual code, about 3000 lines, then a small chunk whcih you insert into a file, where you declare what fields you want to grab (date, title, description). There is also a parameter called "offset", whcih allows you to alter the date whcih is input into the database.

Well this works somewhat, i add/subtract the amount of time needed to get the entry date to be the as my current server time. To test this, i delete the latest entry, then run the file that grabs the entries, it grabs that entry again, and low and behold, the time and date is correct!

The problem is that if I come back the next day, and look at the new entries, they are not using the correct ime again. They are using a time that is hours into the future. I don't know why this is, since the test entry I use had the matched up time. Before this, i thought this Offset paramater was my savior, but alas, it is not.

So I am running out of ideas, my latest idea was to possibly alter the plugin php code itself, so that it totaly ignores the date field in the rss file, and just inserts the current time in unix timestamp, but this code is far to advanced for me.

One of the *important* parts of the code I think I have found is the below. I think it's the code that inserts the values into the database. I was hoping someone might know how insert the current time, instead of that 4 lines of code you see taht has to do with the date.. from entry_date to day lines.

Code: Select all

// Insert into weblog_titles
$data = array(  
	'entry_id'          => '',
	'weblog_id'         => $this->feed_weblog_id,
	'author_id'         => $this->author_id,
	'title'             => $this->post['title'],
	'url_title'         => $this->post['url_title'],
	'ip_address'		    => '127.0.0.1',
	'entry_date'        => ($this->post['date'] - $this->time_offset),
	'year'              => gmdate('Y', $this->post['date'] - $this->time_offset),
	'month'             => gmdate('m', $this->post['date'] - $this->time_offset),
	'day'               => gmdate('d', $this->post['date'] - $this->time_offset),
	'sticky'            => 'n',
	'status'            => $query->row['deft_status'],
	'allow_comments'    => $query->row['deft_comments'],
	'allow_trackbacks'  => $query->row['deft_trackbacks']
);
If there are any questions please ask and I will attempt to answer. As I said, I think this is an important piece of the 3000 lines of code, but I just don't know how to alter it!

Thank you


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

I'd suggest that you shouldn't try to modify the plug-in code.

The code that you showed appears to be part of a PHP class. The notation

Code: Select all

'year' => gmdate('Y', $this->post['date'] - $this->time_offset),
refers first to a PHP function gmdate() that converts the date within the parentheses to Greenwich Mean Time, in this case converting only the year, which would be meaningful only near midnight on the 31st of December, local time. The use of the notation $this-> indicates that it is referring to a property within the same class.

Did you mean to say that test dates were correct when you received them, but when they were inserted into the database, they were incorrect? That part of your explanation wasn't clear to me. I assume that you realize that, once they are in the database, they will not change unless you update the record.
Post Reply