Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Adding threads with xThreads fields (file0 with PHP
Victor Offline
Junior Member
**
Posts: 6
Joined: Aug 2012
Post: #1
Adding threads with xThreads fields (file0 with PHP
Hello.

My little PHP code is:

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
<?php
define('IN_MYBB', true);
define('THIS_SCRIPT', "newthread.php");

global $current_page, $fid, $forum, $plugins, $cache, $_FILES, $mybb;
$fid = 50;
$current_page = "newthread.php";
$mybb->request_method = "post";

include 'global.php';
require_once MYBB_ROOT."inc/functions.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_user.php";
require_once MYBB_ROOT."inc/functions_indicators.php";
require_once MYBB_ROOT."inc/datahandlers/post.php";

$forum = get_forum($fid);

xthreads_gettfcache($fid);
foreach (glob("new_photos/*.txt") as $filename)
{
	$data = unserialize(file_get_contents($filename));

	$_FILES['xthreads_gal_img']['name'] = $data['id'] .".".$data['ext'];
	$_FILES['xthreads_gal_img']['size'] = filesize(MYBB_ROOT."new_photos/" . $data['id'] .".".$data['ext']);
	$_FILES['xthreads_gal_img']['tmp_name'] = MYBB_ROOT."new_photos/" . $data['id'] .".".$data['ext'];

	// Set the thread data that came from the input to the $thread array.
	$new_thread = array(
		"fid" => $fid,
		"xthreads_gal_cat" => $data['category'],
		"xtasel_gal_img" => "file",
		"action" => "do_newthread",
		"xthreads_gal_img" => 1,
		"subject" => $data['title'],
		"icon" => -1,
		"uid" => 878,
		"username" => "Importer fotek",
		"message" => $data['desc'],
		"ipaddress" => get_ip(),
		"posthash" => md5("878".random_str()),
		'savedraft' => 0
	);
	
	$mybb->input = &$new_thread;
	
	$plugins->run_hooks("newthread_do_newthread_start");
	
	$posthandler = new PostDataHandler("insert");
	$posthandler->action = "thread";
	$posthandler->set_data($new_thread);
	
	if($posthandler->validate_thread()) { $posthandler->insert_thread(); } else {var_dump($posthandler->get_errors());}

	$plugins->run_hooks("newthread_do_newthread_end");
}
?>


In txt file in new_photos/ i've got for instance:

Quote:a:6:{s:2:"id";i:1;s:5:"title";s:20:"I się zaczęło :-)";s:4:"date";s:10:"1257760336";s:8:"category";s:38:"2002r - I ogólnopolski zlot - Bemowo ";s:4:"desc";s:438:"I ogólnopolski zlot smartów odbył się 1 maja 2002r. na Lotnisku-Bemowo w Warszawie, przy okazji Zlotu Aut Tuningowych. Było to pierwsze spotkanie klubowe. Po raz pierwszy mieliśmy okazję do spotkania się w trochę większym gronie i zaprezentowania swoich aut. Dwa smarty wzięły również udział w wyścigu na 1/4 mili. Ostatecznie jeden z nich zajął 24 miejsce, co jest bardzo dobrym wynikiem, jak na autko klasy super-mini.";s:3:"ext";s:3:"jpg";}

Everything works great until... it doesn't move upload xthread field file as I want.
[Image: OxzSu.jpg]

I hope developer can help me. It's really hard to understand back-end of xThreads for such programmer as I am.

Looking forward Smile
(This post was last modified: 11-11-2012 10:46 PM by Victor.)
11-11-2012 10:34 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: Adding threads with xThreads fields (file0 with PHP
I suspect it may be breaking because you aren't actually uploading any files - I believe PHP doesn't get fooled if you try to overwrite the $_FILES variable that is, at least with its is_uploaded_file function.

I probably would've just simulated someone actually posting (ie via cURL) if you wanted to do a bulk import, but in the case of XThreads, you could:
a) point it to the URL of the image (rather than the file), or
b) use the special "file://" handler (see the included documentation)

My Blog
11-12-2012 09:32 AM
Find all posts by this user Quote this message in a reply
Victor Offline
Junior Member
**
Posts: 6
Joined: Aug 2012
Post: #3
RE: Adding threads with xThreads fields (file0 with PHP
Mkey. Let's try "file" way.

PHP Code:
"xtasel_gal_img" => "url",
		"xthreads_gal_img" => 0,
		"action" => "do_newthread",
		"xtaurl_gal_img" => "file://" . $data['id'] .".".$data['ext'],


What do i need to specific "url" way? What should I have in xthreads_gal_img? With 0 or without this line it shows:

Quote: ["threadfield_required__0"]=> array(2) { ["error_code"]=> string(23) "threadfield_required__0" ["data"]=> string(8) "Zdjęcie" } }

Cheers.
11-14-2012 01:29 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: Adding threads with xThreads fields (file0 with PHP
I have no clue what $data contains, but ensure you've read the documentation and where the file must be located (uploads/admindrop or something like that).

My Blog
11-14-2012 02:31 PM
Find all posts by this user Quote this message in a reply
Victor Offline
Junior Member
**
Posts: 6
Joined: Aug 2012
Post: #5
RE: Adding threads with xThreads fields (file0 with PHP
uploads/xthreads_ul/admindrop (i've read in documentation) contains 1.jpg file.

PHP Code:
"xtaurl_gal_img" => "file://1.jpg"


Still not working...

Actual version of script:

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
<?php
define('IN_MYBB', true);
define('THIS_SCRIPT', "newthread.php");

global $current_page, $fid, $forum, $plugins, $cache, $_FILES, $mybb;
$fid = 50;
$current_page = "newthread.php";
$mybb->request_method = "post";

include 'global.php';
require_once MYBB_ROOT."inc/functions.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_user.php";
require_once MYBB_ROOT."inc/functions_indicators.php";
require_once MYBB_ROOT."inc/datahandlers/post.php";

$forum = get_forum($fid);

xthreads_gettfcache($fid);
foreach (glob("new_photos/*.txt") as $filename)
{
	$data = unserialize(file_get_contents($filename));

	// Set the thread data that came from the input to the $thread array.
	$new_thread = array(
		"fid" => $fid,
		"xthreads_gal_cat" => $data['category'],
		"xtasel_gal_img" => "url",
		#"xthreads_gal_img" => 1,
		"action" => "do_newthread",
		"xtaurl_gal_img" => "file://" . $data['id'] .".".$data['ext'],
		"subject" => $data['title'],
		"icon" => -1,
		"uid" => 878,
		"username" => "Importer fotek",
		"message" => $data['desc'],
		"ipaddress" => get_ip(),
		"posthash" => md5("878".random_str()),
		'savedraft' => 0
	);
	
	$mybb->input = &$new_thread;
	
	$plugins->run_hooks("newthread_do_newthread_start");
	
	$posthandler = new PostDataHandler("insert");
	$posthandler->action = "thread";
	$posthandler->set_data($new_thread);
	
	if($posthandler->validate_thread()) { $posthandler->insert_thread(); } else {var_dump($posthandler->get_errors());}

	$plugins->run_hooks("newthread_do_newthread_end");
}
?>


Quote:array(1) { ["threadfield_required__0"]=> array(2) { ["error_code"]=> string(23) "threadfield_required__0" ["data"]=> string(8) "Zdjęcie" } }
(This post was last modified: 11-15-2012 01:33 AM by Victor.)
11-15-2012 01:26 AM
Find all posts by this user Quote this message in a reply
Victor Offline
Junior Member
**
Posts: 6
Joined: Aug 2012
Post: #6
RE: Adding threads with xThreads fields (file0 with PHP
Quote:array(20) { ["fid"]=> int(50) ["processed"]=> string(1) "1" ["my_post_key"]=> string(32) "e65e694dc908c3f1f9f8e4a695b49001" ["subject"]=> string(9) "dsadasdas" ["xtasel_gal_img"]=> string(3) "url" ["MAX_FILE_SIZE"]=> string(1) "0" ["xthreads_gal_cat"]=> string(4) "Inne" ["icon"]=> string(2) "-1" ["message_new"]=> string(9) "hgfhgfhfg" ["message"]=> string(9) "hgfhgfhfg" ["postoptions"]=> array(1) { ["subscriptionmethod"]=> string(0) "" } ["numpolloptions"]=> string(1) "2" ["submit"]=> string(13) "Napisz wątek" ["action"]=> string(12) "do_newthread" ["posthash"]=> string(32) "43b26bf325b33fa09df68db1c8bd5eeb" ["attachmentaid"]=> string(0) "" ["attachmentact"]=> string(0) "" ["quoted_ids"]=> string(0) "" ["tid"]=> int(0) ["xthreads_gal_img"]=> int(118) }

What does xThreads set for "xhtreads_gal_img" key?
11-17-2012 05:38 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #7
RE: Adding threads with xThreads fields (file0 with PHP
Ahh.  Try writing your stuff to $_POST before including global.php.
XThreads handles uploads before the posthandler does anything (more specifically, at global_end).


(11-17-2012 05:38 AM)Victor Wrote:  What does xThreads set for "xhtreads_gal_img" key?
It sets it to the actual xtattachment ID (I'm assuming you're performing the var_dump after global.php has been included).

My Blog
11-17-2012 07:26 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: