MyBB Community Forums

Full Version: Handling smilies in creating a post
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using the post handler and the code below to create a thread, whenever there is a smily it drop and fails with a null error, I am wondering what I need to do to handle the smilies



require_once MYBB_ROOT."inc/datahandlers/post.php";
		
		$posthandler = new PostDataHandler("insert");
		$posthandler->action = "thread";

		// Set the thread data that came from the input to the $thread array.
		$new_thread = array(
			"fid" => 16,
			"subject" => "Game Day Chat Archive from ".date('l jS F Y'),
			"prefix" => '',
			"icon" => '',
			"uid" => 1,
			"username" => 'Admin',
			"message" => "This is the archive of the live chat from the game on ".date('l jS F Y')." thank you all for joining in, feel free to continue the discussion",
			"ipaddress" => get_ip(),
			
		);

		$posthandler->set_data($new_thread);

		$valid_thread = $posthandler->validate_thread();
		
		$post_errors = array();
		// Fetch friendly error messages if this is an invalid thread
		if(!$valid_thread)
		{
			$post_errors = $posthandler->get_friendly_errors();
		}
		
		// One or more errors returned, fetch error list and throw to newthread page
		if(count($post_errors) > 0)
		{
			$thread_errors = inline_error($post_errors);
			$mybb->input['action'] = "newthread";
		}
		// No errors were found, it is safe to insert the thread.
		else
		{
			$thread_info = $posthandler->insert_thread();
			$tid = $thread_info['tid'];
			$visible = $thread_info['visible'];
			$pid = $thread_info["pid"];

			// Mark thread as read
			require_once MYBB_ROOT."inc/functions_indicators.php";
			$fid = intval($settings["swmc_forum"]);
			mark_thread_read($tid, $fid);
		}
		
		//so now we have a thread, we can fill it with posts, lets get them all.
		$result = $this->db->query("select uid, shout, timestamp from ".TABLE_PREFIX."inferno_shout where shout NOT LIKE '%has pruned the cheerbox%' order by sid");

		while ($row = $this->db->fetch_array($result))
		{
			$posthandler = new PostDataHandler("insert");

			$user = get_user($row['uid']);
			$post = array(
				"tid" => $tid,
				"replyto" => $pid,
				"fid" => 16,
				"subject" => "Game Day chat reply",
				"icon" => $mybb->input['icon'],
				"uid" => $row['uid'],
				"username" => $user['username'],
				"message" => $row['shout'],
				"ipaddress" => get_ip(),
				
			);
			$posthandler->set_data($post);

			// Now let the post handler do all the hard work.
			$valid_post = $posthandler->validate_post();

			$post_errors = array();
			// Fetch friendly error messages if this is an invalid post
			if(!$valid_post)
			{
				$post_errors = $posthandler->get_friendly_errors();
				
			}
		
			$postinfo = $posthandler->insert_post();
			$pid = $postinfo['pid'];
			$visible = $postinfo['visible'];

			// Mark thread as read
			require_once MYBB_ROOT."inc/functions_indicators.php";
			$fid = intval(16);
			mark_thread_read($tid, $fid);
		
		}	

Never mind the issue was that one of the shoutbox posts was just a smiley so was not reaching the 5 character minimum. I fixed this by adding some padding