Thread Rating:
  • 15 Vote(s) - 3.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[For 1.8] RSS Feed Poster 7.0
#31
That looks like it by the table names but I do not have any SQL code that Alter's the table structure.
Reply
#32
Can we have provision to set max subject length OR it would be better if it chops the text exceeding the subject length?

MyBB default subject length seems 120 characters. I am not sure if its small or enough for a human made subject.

MyBB SQL Error - [20] array ( 'error_no' => 1406, 'error' => 'Data too long for column \'subject\' at row 1', 'query' => ' INSERT INTO mybb_threads (`fid`,`subject`,`prefix`,`icon`,`uid`,`username`,`dateline`,`lastpost`,`lastposter`,`views`,`replies`,`visible`,`notes`) VALUES (\'8\',\'[Business] Should I open up a home equity loan or transfer to new credit card? - Home Equity Loans New - Knowledge Base - HOME EQUITY LOANS BEST RESOURCES\\n \',\'0\',\'0\',\'0\',\'AutoPoster\',\'1281212953\',\'1281212953\',\'AutoPoster\',\'0\',\'0\',\'1\',\'\') ', )
Reply
#33
1.0.1
!Fixed issue if subject line was too long for a feed threw a database error.
Reply
#34
I really want to use this plugin but somehow it has different result as compared to Dennis Tsangs's Rss2Post plugin.

HTML encoding in this plugin is not handled properly.

Subject posted by this plugin is

Afghanistan says to "deal with" security firms (Reuters)

AS COMPARED TO Dennis's plugin

Afghanistan says to "deal with" security firms (Reuters)


Also, when this plugin writes title into post, its written in 2 lines as

Afghanistan says to "deal with" security firms 
(Reuters)

Suggestions:
1. User "content:encoded" becore "description".
2. html decode should be first used on all content.
3. Give option to remove title from post content.
4. If possible, let link posting be removed from post content except the actual article link.
5. Try using one of the ready available rss parsers to make development faster. e.g. SimplePie, last RSS


Great plugin by the way!

Reply
#35
Will need to look into the quote issue. I tend to stay away from third party examples like SimplePie since I like to know the code base.

Update:
1.0.2
!Fixed str_len function error changed it to strlen
Reply
#36
Modifications made in inc/tasks/rssfeedposter.php to fetch PUBLISHED TIME from the feed item and MAKE THIS THE POST DATE:

Insert this function before ?> at the end.
// Function strips unwanted HTML tags and restricts attributes.
function strip_tags_attributes($string,$allowtags=NULL,$allowattributes=NULL){ 
    $string = strip_tags($string,$allowtags); 
    if (!is_null($allowattributes)) { 
        if(!is_array($allowattributes)) 
            $allowattributes = explode(",",$allowattributes); 
        if(is_array($allowattributes)) 
            $allowattributes = implode(")(?<!",$allowattributes); 
        if (strlen($allowattributes) > 0) 
            $allowattributes = "(?<!".$allowattributes.")"; 
        $string = preg_replace_callback("/<[^>]*>/i",create_function( 
            '$matches', 
            'return preg_replace("/ [^ =]*'.$allowattributes.'=(\"[^\"]*\"|\'[^\']*\')/i", "", $matches[0]);'    
        ),$string); 
    } 
    return $string; 
} 

Near line 210-364: Replace the whole if with:
			if ($feeddata != false)
			{

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



					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']) || !isset($context['feeditems'][$i]['link']) || !isset($context['feeditems'][$i]['pubDate']))
								continue;
								
							if(empty($context['feeditems'][$i]['title']) && empty($context['feeditems'][$i]['description']) && empty($context['feeditems'][$i]['pubDate']))
								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 = trim(htmlspecialchars(($feed['html'] ? $context['feeditems'][$i]['title'] : strip_tags($context['feeditems'][$i]['title'])), ENT_QUOTES));

								$msg_body =  strip_tags_attributes(($feed['html'] ? $context['feeditems'][$i]['description'] . "\n" . $context['feeditems'][$i]['link']  : strip_tags($context['feeditems'][$i]['description'] .  "\n" . $context['feeditems'][$i]['link'])), '<em><strong><a><img><br><p><i><b>', 'href,src,target,align');
							
									
								$posthandler = new PostDataHandler("insert");
								$posthandler->action = "thread";
								
								if (strlen($msg_title) > 120)
									$msg_title = substr($msg_title,0,115);
							

								$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" => '',
									"dateline" => strtotime(str_ireplace("GMT", "", $context['feeditems'][$i]['pubDate']))
								);
								
								$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

Finally, replace both of these functions with:
function endElement1($parser, $name)
{
	global $insideitem, $tag, $feedcount, $context;

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

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

	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 "PUBDATE":
				$context['feeditems'][$feedcount]['pubDate'] .= $data;
			break;
		}
	}
}
Reply
#37
Nice addition ImperfectShaun! Thanks for the post.
Reply
#38
I have a problem where the feeds aren't being posted at all.
I have a community called Mount Olympus where you may discuss history and greek mythology.
Reply
#39
Check your error log and task log.

This mod requires either fopen, fscokopen or curl support to work.
Reply
#40
hi
i have a problrm, it dosen't work
iam sure that fopen and curl are supported...
what is the problem?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)