[Question]: How to use Zephyr the right way?

Discuss the development of future releases of phpBB (phpBB 3.x minor releases) and MODing/Coding related questions.
Post Reply
der-nappel
New member
New member
Posts: 1
Joined: 11 Feb 2010, 20:55
Real name: Gregor
Location: Germany (near Frankfurt)
Contact:

[Question]: How to use Zephyr the right way?

Post by der-nappel »

Hi all,

since a week I try to use Zephyr, but I think I´m to stupid for it.. :lol:

I want to use it as a "News-Bot" (User-ID 182). I try to explain my wishes:

At my board is a fixed News-Forum (ID 27), here were all News posted by different Users. The "News-Bot" should reply as the first (and only) one after a few seconds. The message should look like:

Code: Select all

Hi,
please discuss about the News {topic_title} at the [url=Link to new opened Topic]Discuss-Forum[/url]


News-Bot should open the new Topic too (same time like the reply above) at Forum ID=64 with following Text:

Code: Select all

Hi,
here you can Discuss about the News {topic_title}.


Subject of the new should be:

Code: Select all

Discuss:{topic_title}


Is this possible?
My next problem: How I get Zephyr running and where to put it on my root? Only in /includes/crs/ ?
Have I to change something in phpbb_auth_handler and where to put this on my root?

If someone can help me and/or post here the source of the needed changes I would be very happy...

I know, many questions... but please help me.

btw: If you found in my post any errors :arrow: Sorry, my english is not the best...

Regards
Gregor
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: [Question]: How to use Zephyr the right way?

Post by Obsidian »

Okay, I see what you're trying to do. I have to warn you, what you will be needing to do will cause heavy server strain when posting topics in that news forum.

You'll need these two files, and you'll need to place them in the includes/ directory and not a subdirectory of it.
http://trac2.assembla.com/phpbbmodders_lib/browser/phpbb_auth_handler.php
http://trac2.assembla.com/phpbbmodders_lib/browser/class_zephyr.php

Basically, what you're going to want to do is add this code to the required area in posting.php (unfortunately I'm not able to pinpoint the exact location for you, you'll have to discover exactly yourself)

Code: Select all

if(!class_exists('zephyr'))
{
   include($phpbb_root_path . 'includes/class_zephyr.' . $phpEx);
}
if(!class_exists('phpbb_auth_handler'))
{
   include($phpbb_root_path . 'includes/phpbb_auth_handler.' . $phpEx);
}

$zephyr = new zephyr();

//
// begin configuration
//

$reply_topic_forum_id = 27;
$new_topic_forum_id = 64;
$zephyr_subject = 'News bot auto-post';

//$zephyr_topic_title = $topic_title; // you will need to assign $zephyr_topic_title elsewhere with the title of the topic newly created
//$zephyr_reply_topic_id = $some_topic_id_here; // you will need to assign $zephyr_reply_topic_id manually within previous code for the proper reply
$zephyr_user_id = 182;
$zephyr_new_topic_message = "Hi,
here you can Discuss about the News {$zephyr_topic_title}.";

//
// end configuration
//

// our new topic first
$zephyr->set_mode('post');
$zephyr->load_default_data();
if($user_id)
{
    $zephyr->mask_as_user($zephyr_user_id);
}
$zephyr->set_target_forum($new_topic_forum_id);
$zephyr->set_subject(utf8_normalize_nfc($zephyr_subject));
$zephyr->set_message(utf8_normalize_nfc($zephyr_new_topic_message));
$new_topic_id = $zephyr->post();
$zephyr->garbage_collect(true);

//
// begin configuration
//

$zephyr_reply_message = "Hi,
please discuss about the News {$zephyr_topic_title} at the [url=" . generate_board_url() . 'viewtopic.' . $phpEx . "?f={$new_topic_forum_id}&t={$new_topic_id}]Discuss-Forum[/url]";

//
// end configuration
//

// now our reply
$zephyr->set_mode('reply');
$zephyr->load_default_data();
if($user_id)
{
   $zephyr->mask_as_user($zephyr_user_id);
}
$zephyr->set_target_forum($reply_topic_forum_id);
$zephyr->set_target_topic($zephyr_reply_topic_id);
$zephyr->set_subject(utf8_normalize_nfc($zephyr_subject));
$zephyr->set_message(utf8_normalize_nfc($zephyr_reply_message));
$zephyr->post();
$zephyr->garbage_collect(true);


It'll need adapted to what you specifically need to do a little bit, but it should work well. Be sure to read the commenting -- there'll be some things you need to add to other areas in your code in order to get everything to work.

Also, you will need to code an if conditional to check if the post type is that of making a new topic, and if the new topic is being made in the news forum. Just compare the ID's and you should be fine.

I wish you good luck! :beer:
Post Reply