Filter:   InfoImg
download newssource.inc
Language: NonCode
LOC: 0
Project Info
HPE
Server: SourceForge
Type: cvs
[Show Code]






[Show Code]
...ceForge\h\hpe\hpe\hpe1\HPE\
   .cvsignore
   clickerr.inc
   config.inc
   Config_File.class.php
   database.inc
   database.mysql.inc
   database.pear.inc
   FormChek.js
   HPE.inc
   HPEbase.inc
   HPEUsers.default.xml
   HPEUsers.guest.xml
   layout.js
   local.inc
   modules.inc
   ...andlers.addChannel.ftsc
   navcond.js
   newsaccess.inc
   newssource.inc
   newstools.js
   overlib.js
   overlib_mini.js
   pagemaker.inc
   pages.inc
   PHPClientSniffer.inc
   phpodp.inc
   publisher.inc
   services.inc
   sitelister.inc
   Smarty.addons.php
   Smarty.class.php
   Smarty_Compiler.class.php
   sourcetools.js
   thememaker.inc
   toparser.inc
   user.edit.inc
   user.inc
   xmlrpc.inc
   xmlrpcs.inc
   xmltree.inc

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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
<?
/*

HPE - News Portal Engine
Copyright (C) 2000-2001 Mike Krus

This program is free software; it is distributed in the hope 
that it will be useful, but WITHOUT ANY WARRANTY; without 
even the implied warranty of MERCHANTABILITY or FITNESS 
FOR A PARTICULAR PURPOSE.  

READ LICENSE.TXT IN THE BASE DIRECTORY FOR INFORMATION 
ABOUT REDISTRIBUTING THIS SOURCE CODE

*/

require_once "$HPEinc/newsaccess.inc";

class HPENewsSource
{
	var $id = 0;
	var $name = "";
	var $url = "";
	var $host = "";
	var $port = 80;
	var $path = "";
	var $header = "";
	var $source = "";
	var $language = "en";

	var $maxitems = 0;
	var $timeout = 21600;
	var $level = 0;

	var $type = 0;
	var $typendx = 0;
	var $isxml = 0;
	var $flags = 0;

	var $param1 = "";
	var $param2 = "";
	var $param3 = "";
	var $description = "";
	var $icon = "";
	var $limitdesc = 0;

	var $editor = 0;
	var $categorie = 0;
	var $reqcomment = "";
	var $branding = "";

	var $adddate = "NOW()";
	var $moddate = "NOW()";

	var $cachefile = "";	// where to cache the data


	var $thetitle;			// parsed title for the source
	var $thelink;			// parsed link
	var $filedate = 0;		// date of parse

	var $itemcount = 0;		// number of newly parsed items
	var $data;				// array of parsed data

	var $urating = 0;		// user ratting
	var $uratingvotes = 0;	// number of votes


	function HPENewsSource()
	{
	}


	function init()
	{
		$this->id = 0;
		$this->syndic8id = 0;
		$this->name = "";
		$this->url = "";
		$this->host = "";
		$this->port = 80;
		$this->path = "";
		$this->header = "";
		$this->source = "";
		$this->language = "en";

		$this->type = 0;
		$this->typendx = 0;
		$this->isxml = 0;
		$this->maxitems = 0;
		$this->timeout = 1800;
		$this->flags = 0;

		$this->param1 = "";
		$this->param2 = "";
		$this->param3 = "";
		$this->description = "";
		$this->icon = "";

		$this->level = 0;
		$this->limitdesc = 0;

		$this->editor = 0;
		$this->categorie = 0;

		$this->branding = "";
		$this->template = "";
		$this->reqcomment = "";

		$this->cachefile = "";
		$this->thetitle = "";
		$this->thelink = "";

		$this->itemcount = 0;
		$this->data = array();

		$this->urating = 0;
		$this->uratingvotes = 0;
	}


	function read($id)
	{
		if($id == $this->id)
			return HPENPidle;
		$this->id = 0;

		global $HPEtheDB;
		global $HPEinc;
		global $HPEtheConfig;

		$this->init();

		$cache = $this->makecachepath($id, "inc");

		if(file_exists($cache)) 
		{
			include $cache;
		} 
		else 
		{
			$query = "SELECT * FROM $HPEtheDB->dbtnewssites WHERE siteid=$id";
			$row = $HPEtheDB->one_array($query);
			if($row) 
			{
				$this->id = $id;

				$this->name = stripslashes($row["sitename"]);
				$this->source = $row["source"];
				$this->url = $row["siteurl"];
				$this->host = $row["sitehost"];
				$this->port = $row["siteport"];
				$this->path = $row["newspath"];
				$this->header = $row["header"];
				$this->language = strtolower($row["language"]);

				$this->type = $row["newstype"];
				$n = count($HPEtheConfig->newsparsers);
				for($i=0; $i<$n; $i++)
					if($HPEtheConfig->newsparsers[$i]["id"] == $this->type) 
						break;
				if($i != $n) $this->typendx = $i;
						else $this->typendx = -1;

				$this->categorie = $row["categorie"];
				$this->maxitems = $row["maxitems"];
				$this->timeout = $row["timeout"];
				$this->param1 = $row["param1"];
				$this->param2 = $row["param2"];
				$this->param3 = $row["param3"];
				$this->description = $row["description"];
				$this->icon = $row["icon"];
				$this->flags = $row["flags"];
				$this->level = $row["level"];
				$this->limitdesc = $row["limitdesc"];

				$this->reqcomment = $row["reqcomment"];
				$this->branding = $row["branding"];

				$this->adddate = $row["adddate"];
				$this->moddate = $row["moddate"];

				$this->urating = $row["urating"];
				$this->computeUserRating();

				$this->editor = $row["editor"];
				$this->editoricon = "";
				$this->editorlink = "";
				$this->editorname = "";
				if($this->editor)
				{
					if($row = $HPEtheDB->one_array("SELECT * FROM $HPEtheDB->dbtnewspublisher WHERE pubid=$this->editor")) 
					{
						$this->editoricon = $row["icon"];
						$this->editorlink = $row["url"];
						$this->editorname = $row["name"];
					}
					else $this->editor = 0;
				}

		        if($this->type == 0 || $this->type == 9) $this->isxml = 1;
		        elseif(stristr($this->path, "rss") || stristr($this->path, "xml"))  $this->isxml = 1;
		        else $this->isxml = 0;

				$this->syndic8id = $HPEtheDB->one_data("SELECT syndic8id FROM $HPEtheDB->dbtsyndic8 WHERE hpeid=$id");

				$cf = @fopen($cache, "w");
				if($cf)
				{
					flock($cf, 2);
					fputs($cf, "<?\n\n" );

					fputs($cf, "\$this->name = '" . escquotes($this->name) . "';\n" );
					fputs($cf, "\$this->url = '$this->url';\n" );
					fputs($cf, "\$this->source = '$this->source';\n" );
					fputs($cf, "\$this->host = '$this->host';\n" );
					fputs($cf, "\$this->port = $this->port;\n" );
					fputs($cf, "\$this->path = '$this->path';\n" );
					fputs($cf, "\$this->header = '" . addslashes($this->header) . "';\n" );
					fputs($cf, "\$this->language = '$this->language';\n" );

					fputs($cf, "\$this->id = $this->id;\n" );
					fputs($cf, "\$this->level = $this->level;\n" );
					fputs($cf, "\$this->limitdesc = $this->limitdesc;\n" );
					fputs($cf, "\$this->type = $this->type;\n" );
					fputs($cf, "\$this->typendx = $this->typendx;\n" );
					fputs($cf, "\$this->isxml = $this->isxml;\n" );
					fputs($cf, "\$this->maxitems = $this->maxitems;\n" );
					fputs($cf, "\$this->timeout = $this->timeout;\n" );
					fputs($cf, "\$this->flags = $this->flags;\n" );
					fputs($cf, "\$this->editor = $this->editor;\n" );
					fputs($cf, "\$this->editoricon = '" . addslashes($this->editoricon) . "';\n" );
					fputs($cf, "\$this->editorlink = '" . addslashes($this->editorlink) . "';\n" );
					fputs($cf, "\$this->editorname = '" . addslashes($this->editorname) . "';\n" );
					fputs($cf, "\$this->categorie = $this->categorie;\n" );

					fputs($cf, "\$this->branding = '$this->branding';\n" );
					fputs($cf, "\$this->param1 = '" . escquotes($this->param1) . "';\n" );
					fputs($cf, "\$this->param2 = '" . escquotes($this->param2) . "';\n" );
					fputs($cf, "\$this->param3 = '" . escquotes($this->param3) . "';\n" );
					fputs($cf, "\$this->description = '" . addslashes($this->description) . "';\n" );
					fputs($cf, "\$this->reqcomment = '" . addslashes($this->reqcomment) . "';\n" );
					fputs($cf, "\$this->icon = '$this->icon';\n" );

					fputs($cf, "\$this->urating = $this->urating;\n" );
					fputs($cf, "\$this->uratingvotes = $this->uratingvotes;\n" );

					fputs($cf, "\$this->syndic8id = $this->syndic8id;\n" );

					fputs($cf, "\n?>\n" );

					flock($cf, 3);
					fclose($cf);
				}
			}
			else
			{
				if($HPEtheConfig->errorall)
					echo "$HPEtheDB->dberr<BR>\n";
				return HPENPnodbinfo;
			}

		}

		if($this->flags & HPENewsDisable && !$HPEtheConfig->errorall)
		{
			$this->init();
			return HPENPnodbinfo;
		}

		$this->cachefile = $this->makecachepath($id, "spd");

		return HPENPidle;
	}


	function makecachepath($id, $ext="spd")
	{
		global $HPEinc;
		global $HPEtheConfig;
		global $HPEtheDB;

		$cache = "$HPEtheConfig->cachepath/$HPEtheDB->dbtnewssites/";
		$cache .= sprintf("%03d", ($id % 100));

		if(!@is_dir($cache)) mkdir($cache, 0777);
		if(!@is_writable($cache)) die("Can't write to dir $cache");

		$cache .= "/$id.$ext";

		return $cache;
	}


	function loadnews($id, $maxitems = 0)
	{
		if($this->id != $id) 
			$res = $this->read($id);
		if($this->id) {
			return $this->loadCache();
		} else return $res;
	}


	// if the cache is valid, this loads the cache file
	function loadCache()
	{
		if(file_exists($this->cachefile) == false) 
			return HPENPnocache;

		if(HPELoadSingleNews($data, $this->id) == 0)
			return HPENPemptycache;

		$this->data = $data["items"];
		$this->thetitle = $data["title"];
		$this->thelink  = $data["link"];
		$this->filedate  = $data["lastupdate"];
		$this->itemcount = $data["itemcount"];

		unset($data);

		$this->status = HPENPfromcache;
		return HPENPidle;
	}


	function updateDB()
	{
		global $HPEtheDB;
		$today = date("Ymdhis");
		$query = "UPDATE $HPEtheDB->dbtnewssites SET " .
					"sitename=" . $HPEtheDB->escapeString($this->name) . ", " .
					"moddate=$today, " .
					"source='$this->source', " .
					"sitehost='$this->host', " .
					"siteport=$this->port, " .
					"newspath='$this->path', " .
					"header='$this->header', " .
					"newstype=$this->type, " .
					"description=" . $HPEtheDB->escapeString($this->desc) . ", " .
					"param1='$this->param1', " .
					"param2='$this->param2', " .
					"param3='$this->param3', " .
					"siteurl='$this->url', " .
					"categorie=$this->categorie, " .
					"language='$this->language', " .
					"icon='$this->icon', " .
					"timeout=$this->timeout, " .
					"flags=$this->flags, " .
					"editor=$this->editor, " .
					"branding='$this->branding', " .
					"level=$this->level, " .
					"limitdesc=$this->limitdesc, " .
					"maxitems=$this->maxitems " .
				  "WHERE siteid=$this->id";
		$res = $HPEtheDB->query($query);
		return !$HPEtheDB->iserror($res);
	}


	function createDB()
	{
		global $HPEtheDB;

		if($this->id == 0)
			die("must give source a siteid");

		$today = date("Ymdhis");
		$query = "INSERT INTO $HPEtheDB->dbtnewssites " .
					"(siteid, adddate, sitename, moddate, source, sitehost, siteport, newspath, " .
						"header, newstype, description, param1, param2, param3, siteurl, categorie, language, " .
						"icon, timeout, flags, editor, maxitems, branding) VALUES " .
					"($this->id, $today, " . $HPEtheDB->escapeString($this->name) . ", $today, '$this->source', " .
						"'$this->host', $this->port, '$this->path', '$this->header', $this->type, " .
						$HPEtheDB->escapeString($this->desc) . ", '$this->param1', '$this->param2', '$this->param3', " .
						"'$this->url', $this->categorie, '$this->language', '$this->icon', $this->timeout, " .
						"$this->flags, $this->editor, $this->maxitems, '$this->branding')";
		$res = $HPEtheDB->query($query);
		return !$HPEtheDB->iserror($res);
	}


	function computeUserRating()
	{
		global $HPEtheDB;

		$total = 0;
		$this->uratingvotes = 0;
		$this->urating = 0;

		$result = $HPEtheDB->query("SELECT * FROM $HPEtheDB->dbtnewspoll WHERE siteid=$this->id");
		if(!$HPEtheDB->iserror($result) && $HPEtheDB->getrowcount($result)) 
		{
			while($row = $HPEtheDB->getrow($result)) 
			{
				$this->uratingvotes += $row["optionCount"];
				$total += $row["voteID"] * $row["optionCount"];
			}
			$this->urating = (int) ($total / $this->uratingvotes);
		}
	}


	function uvote($vote)
	{
		global $HPEtheDB;
		global $HPEinc;
		global $HPEtheConfig;

		$query = "UPDATE $HPEtheDB->dbtnewspoll SET optionCount=optionCount+1 WHERE siteid=$this->id AND voteID=$vote";
		$res = $HPEtheDB->query($query);
		if($HPEtheDB->iserror($res) || $HPEtheDB->getaffectedrowcount() == 0) 
		{
			$query = "INSERT INTO $HPEtheDB->dbtnewspoll (siteid, voteID, optionCount) VALUES " .
					 "($this->id, $vote, 1)";
			$HPEtheDB->query($query);
		}
		$this->computeUserRating();

		$cache = $this->makecachepath($this->id, "inc");
		@unlink($cache);
	}


	function GetItemTableCode()
	{
		return date("w");
	}

};

?>