PDA

View Full Version : Attachments With RSS postings


neopets
09-20-2008, 10:18 AM
So I have a specific RSS feed that includes one image in each feed that I'd like to attach to the new thread being created.

In includes/cron/rssposeter.php

// insert item as thread
case 'thread':
default:
{
if($feed['special'] == 1){

$poststarttime = TIMENOW;
$posthash = md5($poststarttime . $feed['userid'] . $vbulletin->userinfo['salt']);
$postinfo = array('posthash' => $posthash);
$forumid = $feed['forumid'];
$foruminfo = fetch_foruminfo($forumid);

$zimage = file_get_contents($ximage[1][0]);

$filenamez = basename($ximage[1][0]);

$fp = fopen('/tmp/'.$filenamez, 'w');
fwrite($fp, $zimage);
fclose($fp);

$tmp_name = '/tmp/'.$filenamez;
$fsize = filesize($tmp_name);

require_once(DIR . '/includes/class_upload.php');
require_once(DIR . '/includes/class_image.php');

$attachdata =& datamanager_init('Attachment', $vbulletin, ERRTYPE_ARRAY);
$upload =& new vB_Upload_Attachment($vbulletin);
$image =& vB_Image::fetch_library($vbulletin);

$upload->data =& $attachdata;
$upload->image =& $image;


$upload->foruminfo =& $foruminfo;
$upload->postinfo =& $postinfo;
$attachment = array(
'name' =>& $filenamez,
'tmp_name' =>& $tmp_name,
'error' =>& $zok,
'size' =>& $fsize,
);

if ($attachmentid = $upload->process_upload($attachment)) {
$itemdata->set_info('attachmentid', $attachmentid);
}
else {
exit;
}

}

// init thread/firstpost datamanager
$itemdata =& datamanager_init('Thread_FirstPost', $vbulletin, $error_type, 'threadpost');
$itemdata->set_info('forum', fetch_foruminfo($feed['forumid']));
$itemdata->set_info('user', $feed);
$itemdata->set_info('is_automated', 'rss');
$itemdata->set_info('chop_title', true);
$itemdata->set('iconid', $feed['iconid']);
$itemdata->set('sticky', ($feed['rssoptions'] & $vbulletin->bf_misc_feedoptions['stickthread'] ? 1 : 0));
$itemdata->set('forumid', $feed['forumid']);
$itemdata->set('prefixid', $feed['prefixid']);
$itemdata->set('userid', $feed['userid']);
$itemdata->set('title', strip_bbcode(convert_wysiwyg_html_to_bbcode($feed['xml']->parse_template($feed['titletemplate'], $item))));
$itemdata->set('pagetext', $pagetext);
$itemdata->set('visible', ($feed['rssoptions'] & $vbulletin->bf_misc_feedoptions['moderatethread'] ? 0 : 1));
$itemdata->set('allowsmilie', ($feed['rssoptions'] & $vbulletin->bf_misc_feedoptions['allowsmilies']) ? 1 : 0);
$itemdata->set('showsignature', ($feed['rssoptions'] & $vbulletin->bf_misc_feedoptions['showsignature']) ? 1 : 0);
$itemdata->set('ipaddress', '');
$threadactiontime = (($feed['threadactiondelay'] > 0) ? (TIMENOW + $feed['threadactiondelay'] * 3600) : 0);

if ($itemid = $itemdata->save())
{
$itemtype = 'thread';
$itemtitle = $itemdata->fetch_field('title');
$itemlink = "../showthread.php?t=$itemid";

if (defined('IN_CONTROL_PANEL'))
{
echo "<li><a href=\"$itemlink\" target=\"feed\">$itemtitle</a></li>";
}

$rsslog_insert_sql[] = "($item[rssfeedid], $itemid, '$itemtype', '" . $vbulletin->db->escape_string($uniquehash) . "', '" . $vbulletin->db->escape_string($item['contenthash']) . "', " . TIMENOW . ", $threadactiontime)";
$cronlog_items["$item[rssfeedid]"][] = "\t<li>$vbphrase[$itemtype] <a href=\"$itemlink\" target=\"logview\"><em>$itemtitle</em></a></li>";
}
break;
}
}


The part in
if($feed['special'] == 1){

I know I'm getting the image and storing it properly. I'm not storing the attachment correctly.

I think it's because the code is meant for the image using $vbulletin->input->clean_gpc('f', 'attachment', TYPE_FILE);

But since I'm using an rss feed to create an image there is no $_FILE

Anyone know how I can fix this? It stops at the exit command. Means $upload->process_upload is not working