[SOLVED] I need help with this code
Divvy Offline
Junior Member
**
Posts: 37
Joined: Jan 2012
Post: #1
[SOLVED] I need help with this code
Hello guys,

I have installed this plugin to auto post content using RSS Feeds:
http://mods.mybb.com/view/rss-feed-poster

But I need a little change and I dont know how to do It...

This is an example of one of my auto posts:
[Image: EbT8t.png]

I want to change the source link http:// with "Read More...".
I think that we need to modify ['link'] in task rssfeedposter.php file, but dont know how to do It...
Can someone please help me?
Thank you!

rssfeedposter.php code:

PHP Code:
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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
<?php
/*
RSS Feed Poster
by: vbgamer45
http://www.mybbhacks.com
Copyright 2010  MyBBHacks.com

############################################
License Information:

Links to http://www.mybbhacks.com must remain unless
branding free option is purchased.
#############################################
*/

$feedcount = 0;
$maxitemcount = 0;
$tag = '';
$tag_attrs = '';
$insideitem = false;
$depth = array();



function verify_rss_url($url)
{
	global $txt, $depth;

	// Rss Data storage
	$finalrss = '';
	$failed = true;

		$fp2 = @fopen($url, "r");
		if ($fp2)
		{
			$failed = false;
			$contents = '';
			while (!feof($fp2))
			{
			  $contents .= fread($fp2, 8192);
			}
	
			fclose($fp2);
	
			$finalrss = $contents;
		}
	



		if($failed == true)
		{
			$url_array = parse_url($url);
	
			$fp = @fsockopen($url_array['host'], 80, $errno, $errstr, 30);
			if (!$fp)
			{
	
			}
			else
			{
				$failed = false;
	
			   $out = "GET " . $url_array['path'] . (@$url_array['query'] != '' ? '?' . $url_array['query'] : '') . "  HTTP/1.1\r\n";
			   $out .= "Host: " . $url_array['host'] . "\r\n";
			   $out .= "Connection: Close\r\n\r\n";
	
			   fwrite($fp, $out);
	
			   $rssdata = '';
			   
		   $header = '';
		   // Remove stupid headers.
		   	do 
			{
				$header .= fgets ($fp, 128 );

		 	 } while ( strpos($header, "\r\n\r\n" ) === false );
	
			   while (!feof($fp))
			   {
			       $rssdata .= fgets($fp, 128);
			   }
			   fclose($fp);
	
			   @$finalrss = @$rssdata;
	
			}
		}
	

	// Use cURL

		if($failed == true)
		{
			if(function_exists("curl_init"))
			{
				$failed = false;
				// Last but not least try cUrl
				$ch = curl_init();
	
				// set URL and other appropriate options
				curl_setopt($ch, CURLOPT_URL, $url);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	
				// grab URL, and return output
				$output = curl_exec($ch);
	
				// close curl resource, and free up system resources
				curl_close($ch);
				return $output;
			}
		}




	// XML Parser functions to verify the XML Feed
	if($failed == false)
	{
		$depth = array();

		$xml_parser = xml_parser_create();
		xml_set_element_handler($xml_parser, "startElement2", "endElement2");


		   if (!xml_parse($xml_parser, $finalrss)) {
		      fatal_error(sprintf($txt['feedposter_err_xmlerror'],
		                   xml_error_string(xml_get_error_code($xml_parser)),
		                   xml_get_current_line_number($xml_parser)), false);
		   }

		xml_parser_free($xml_parser);
	}
	else
	{
		// We were not able to download the feed :(
		
	}


}


function startElement2($parser, $name, $attrs)
{
   global $depth;
   $depth[$parser]++;
}

function endElement2($parser, $name)
{
   global $depth;
   $depth[$parser]--;
}

function UpdateRSSFeedBots($task)
{
	global $db, $context, $feedcount, $maxitemcount, $insideitem, $tag, $tag_attrs;

	// First get all the enabled bots
	$context['feeds'] = array();
	$request = $db->write_query("
			SELECT
				ID_FEED, fid, feedurl, title, postername, updatetime, enabled, html,
				uid, locked, articlelink, topicprefix, numbertoimport, importevery, markasread 
			FROM ".TABLE_PREFIX."feedbot
			WHERE enabled = 1");

	while ($row = $db->fetch_array($request))
	{
		$context['feeds'][] = $row;
	}

	

	require_once MYBB_ROOT."inc/datahandlers/post.php";
	

	// Check if a field expired
	foreach ($context['feeds'] as $key => $feed)
	{

		$current_time = time();


		// If the feedbot time to next import has expired
		//add_task_log($task, "Check " . ($current_time + (60 * $feed['importevery'])) . " :" . $feed['updatetime']);
		
		if ($current_time > $feed['updatetime'])
		{

			$feeddata = GetRSSData($feed['feedurl']);



			if ($feeddata != false)
			{

				// Process the XML
					$xml_parser = xml_parser_create();
					$context['feeditems'] = array();
					$feedcount = 0;
					$maxitemcount = $feed['numbertoimport'];
					$tag = '';
					$tag_attrs = '';
					$insideitem = false;
					$context['feeditems'][0] = array();
					$context['feeditems'][0][] = array();
					$context['feeditems'][0]['title'] = '';
					$context['feeditems'][0]['description'] = '';
					$context['feeditems'][0]['link'] = '';



					xml_set_element_handler($xml_parser, "startElement1", "endElement1");
					xml_set_character_data_handler($xml_parser, "characterData1");

					if (!xml_parse($xml_parser, $feeddata))
					 {
						// Error reading xml data

					     xml_parser_free($xml_parser);
					 }
					else
					{
					   	// Data must be valid lets extra some information from it
					   	// RSS Feeds are a list of items that might contain title, description, and link


					   	// Free the xml parser memory
						xml_parser_free($xml_parser);

						// Loop though all the items
						$myfeedcount = 0;

						for ($i = 0; $i < ($feedcount); $i++)
						{
							

							if ($myfeedcount >= $maxitemcount)
							{
								continue;
							}
							
							//add_task_log($task, "NotSkip: $myfeedcount : $maxitemcount : $feedcount  T:" . $context['feeditems'][$i]['title']);

							
							// Check feed Log
							// Generate the hash for the log
							if(!isset($context['feeditems'][$i]['title']) || !isset($context['feeditems'][$i]['description']))
								continue;
								
							if(empty($context['feeditems'][$i]['title']) && empty($context['feeditems'][$i]['description']))
								continue;	
								
							

							$itemhash = md5($context['feeditems'][$i]['title'] . $context['feeditems'][$i]['description']);
							$request = $db->write_query("
							SELECT
								feedtime
							FROM ".TABLE_PREFIX."feedbot_log
							WHERE feedhash = '$itemhash'");


							// If no has has found that means no duplicate entry
							if ($db->num_rows($request) == 0)
							{

								// Create the Post
								$msg_title = ($feed['html'] ? $context['feeditems'][$i]['title'] : strip_tags($context['feeditems'][$i]['title']));

								$msg_body =  ($feed['html'] ? $context['feeditems'][$i]['description'] . "\n\n" . $context['feeditems'][$i]['link']  : strip_tags($context['feeditems'][$i]['description'] .  "\n\n" . $context['feeditems'][$i]['link']));
							
									
								$posthandler = new PostDataHandler("insert");
								$posthandler->action = "thread";
								
								if (strlen($msg_title) > 120)
									$msg_title = substr($msg_title,0,115);
								
								$msg_title = trim($msg_title);
							

								$new_thread = array(
									"fid" => $feed['fid'],
									"subject" => $feed['topicprefix'] . $msg_title,
									"icon" => '',
									"uid" => $feed['uid'],
									"username" => $feed['postername'],
									"message" => '[b]' . $msg_title . "[/b]\n\n" . $msg_body,
									"ipaddress" => '127.0.0.1',
									"posthash" => ''
								);
								
								$new_thread['modoptions']  = array('closethread' => $feed['locked']);
								
								$posthandler->set_data($new_thread);
								$valid_thread = $posthandler->validate_thread();
								
								if(!$valid_thread)
								{
									$post_errors = $posthandler->get_friendly_errors();
								}
								else 
									$thread_info = $posthandler->insert_thread();
									
									
								$tid = (int) $thread_info['tid'];
								$pid = (int)  $thread_info['pid'];
								
								if ($feed['markasread'])
								{
									// Mark thread as read
									require_once MYBB_ROOT."inc/functions_indicators.php";
									mark_thread_read($tid, $feed['fid']);
								}

								// Add Feed Log
								$fid = $feed['ID_FEED'];
								$ftime = time();

								$db->write_query("
								INSERT INTO ".TABLE_PREFIX."feedbot_log
									(ID_FEED, feedhash, feedtime, tid, pid)
								VALUES
									($fid,'$itemhash',$ftime,$tid,$pid)");
								
								$myfeedcount++;

							}
						}

					 } // End valid XML check



			}  // End get feed data
			
			
			
			// Set the RSS Feed Update time
			$updatetime = time() +  (60 * $feed['importevery']);
			
			
			$db->write_query("
			UPDATE ".TABLE_PREFIX."feedbot 
			SET 
				updatetime = '$updatetime'
		
			WHERE ID_FEED = " . $feed['ID_FEED']);

		} // End expire check


	} // End for each feed

}

function GetRSSData($url)
{
	$url_array = parse_url($url);
	

		$fp2 = @fopen($url, "r");
		if ($fp2)
		{
			$contents = '';
			while (!feof($fp2))
			{
			  $contents .= fread($fp2, 8192);
			}
	
			fclose($fp2);
	
			return $contents;
		}



		$fp = fsockopen($url_array['host'], 80, $errno, $errstr, 30);
		if (!$fp)
		{
	
		}
		else
		{
	
	
		   $out = "GET " . $url_array['path'] . (@$url_array['query'] != '' ? '?' . $url_array['query'] : '') . "  HTTP/1.1\r\n";
		   $out .= "Host: " . $url_array['host'] . "\r\n";
		   $out .= "Connection: Close\r\n\r\n";
	
		   fwrite($fp, $out);
	
		   $rssdata = '';
		   
		   $header = '';
		   // Remove stupid headers.
		   	do 
			{
				$header .= fgets ($fp, 128 );

		 	 } while ( strpos($header, "\r\n\r\n" ) === false );
	
		   while (!feof($fp))
		   {
		       $rssdata .= fgets($fp, 128);
		   }
		   fclose($fp);

		   $finalrss = $rssdata;
	
		   return  $finalrss;
		}
	


		if(function_exists("curl_init"))
		{
			// Last but not least try cUrl
			$ch = curl_init();
	
			// set URL and other appropriate options
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	
			// grab URL, and return output
			$output = curl_exec($ch);
	
			// close curl resource, and free up system resources
			curl_close($ch);
			
			return $output;
		}
	


	// Failure return false
	return false;

}

function startElement1($parser, $name, $attrs)
 {
	global $insideitem, $tag, $tag_attrs;
	if ($insideitem)
	{
		$tag = $name;
		$tag_attrs =  $attrs;
	}
	elseif ($name == "ITEM"  || $name == "ENTRY")
	{
		$insideitem = true;
	}
}

function endElement1($parser, $name)
{
	global $insideitem, $tag, $feedcount, $context, $tag_attrs;

	if ($name == "ITEM" || $name == "ENTRY")
	{
		$feedcount++;
		$context['feeditems'][$feedcount] = array();
		$context['feeditems'][$feedcount][] = array();
		$context['feeditems'][$feedcount]['title'] = '';
		$context['feeditems'][$feedcount]['description'] = '';
		$context['feeditems'][$feedcount]['link'] = '';
		$tag_attrs = '';
		$insideitem = false;
	}
}

function characterData1($parser, $data)
 {
	global $insideitem, $tag,  $feedcount, $context, $maxitemcount, $tag_attrs;

	if ($insideitem )
 	{
		switch ($tag)
		{
			case "TITLE":
				$context['feeditems'][$feedcount]['title'] .= $data;
			break;

			case "DESCRIPTION":
				$context['feeditems'][$feedcount]['description'] .= $data;

			break;

			case "LINK":
				$context['feeditems'][$feedcount]['link'] .= $data;
			break;
			
			case "SUMMARY":
			$context['feeditems'][$feedcount]['description'] .= $data;

			break;
			case "CONTENT":
			$context['feeditems'][$feedcount]['description'] .= $data;

			break;

			case "LINK":
				$data = trim($data);
				$context['feeditems'][$feedcount]['link'] .= $data;
				IF (empty($data) && isset($tag_attrs['HREF']))
					$context['feeditems'][$feedcount]['link'] .= $tag_attrs['HREF'];
				
				
			break;
			
		}
	}
}



function task_rssfeedposter($task)
{
	global $lang;
	
	$lang->load('rssfeedposter');
	
	UpdateRSSFeedBots($task);
	
	add_task_log($task, $lang->rssfeedposter_taskran);
}
?>


Can someone please help me?
Thank you! Smile

(This post was last modified: 01-14-2012 06:08 AM by Divvy.)
01-14-2012 03:16 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #2
RE: I need help with this code
Try this:
Replace:

PHP Code:
274
$msg_body =  ($feed['html'] ? $context['feeditems'][$i]['description'] . "\n\n" . $context['feeditems'][$i]['link']  : strip_tags($context['feeditems'][$i]['description'] .  "\n\n" . $context['feeditems'][$i]['link']));

With:

PHP Code:
274
$msg_body =  ($feed['html'] ? $context['feeditems'][$i]['description'] . "\n\n[url=".trim($context['feeditems'][$i]['link'])."]Read More....[/url]"  : strip_tags($context['feeditems'][$i]['description'] .  "\n\n[url=".trim($context['feeditems'][$i]['link'])."]Read More....[/url]"));


01-14-2012 04:04 AM
Find all posts by this user Quote this message in a reply
Divvy Offline
Junior Member
**
Posts: 37
Joined: Jan 2012
Post: #3
RE: I need help with this code
Is working great!!! Thank you my friend Biggrin
Great forum, great support!!!
01-14-2012 05:48 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: