Skip to main content
Topic: Temporary hooks listing/documentation (Read 32133 times) previous topic - next topic
0 Members and 3 Guests are viewing this topic.

Re: Temporary hooks listing/documentation

Reply #30

Yes, I do. It wasn't my first word choice, but it seemed consistent with the other integrate_bla_buttons functions. ;)

Re: Temporary hooks listing/documentation

Reply #31

Quote from: Frenzie – Where should I stick the debug variable, btw?
Settings.php
Bugs creator.
Features destroyer.
Template killer.

Re: Temporary hooks listing/documentation

Reply #32

I myself don't comprehend most of them especially where there exist other methods that are not even using the word call_integration_hook or integrate_bla_bla in the codes.  I am trying to learn them, though it will take me some longer times.  :-[

Re: Temporary hooks listing/documentation

Reply #33

Alrighty, it's working! :)

Code: [Select]
	public static function profile_areas(&$profile_areas)
{
global $txt, $scripturl, $memID, $modSettings;
loadLanguage('StopSpammer');

$profile_areas['profile_action']['areas'] = elk_array_insert($profile_areas['profile_action']['areas'], 'activateaccount', array(
'checkmember' => array(
'label' => $txt['stopspammer_profilecheck'],
'custom_url' => $scripturl . '?action=admin;area=viewmembers;sa=query;params=' . base64_encode(serialize(array('mem_id' => $memID, 'types' => array('mem_id' => '=')))),
'enabled' => !empty($modSettings['stopspammer_enable']),
'sc' => 'get',
'permission' => array(
'own' => array('profile_remove_any', 'profile_remove_own'),
'any' => array('profile_remove_any', 'moderate_forum'),
),
)), 'after');
}

I might have to reacquaint myself with templates, but that's for another day.

To put some pressure on myself, here's what I've been working on today: https://github.com/Frenzie/elk-stop-spammer It's been going a bit slower than I would've liked but could be worse.

Re: Temporary hooks listing/documentation

Reply #34

I'm having some trouble understanding how to modify lists. In ManageMembers.controller.php there's a list we can hook into: https://github.com/elkarte/Elkarte/blob/5fe7f404bb3b4c5e9a570edc48207c6cde663429/sources/admin/ManageMembers.controller.php#L586

So I did, and the $listOptions adjusts fine, but the output stays the same.
Code: [Select]
	public static function list_member_list($listOptions)
{
//print_r($listOptions);
$listOptions['columns']['user_name']['data']['sprintf']['format'] .= 'asdf';
//print_r($listOptions);
}

Edit: Doh! I noticed the typo as soon as I posted this. I forgot the &.  :-[

Re: Temporary hooks listing/documentation

Reply #35

@emanuele

I don't think I'm missing a hook to affect this DB query because there's no variable: https://github.com/elkarte/Elkarte/blob/5fe7f404bb3b4c5e9a570edc48207c6cde663429/sources/subs/Members.subs.php#L1160-L1164

In other words, I don't think I can convert this source mod into a hook:
Code: [Select]
		<operation>
<search position="replace"><![CDATA[
mem.id_member, mem.member_name, mem.real_name, mem.email_address, mem.icq, mem.aim, mem.yim, mem.msn, mem.member_ip, mem.member_ip2, mem.last_login,]]></search>
<add><![CDATA[
mem.id_member, mem.member_name, mem.real_name, mem.email_address, mem.icq, mem.aim, mem.yim, mem.msn, mem.member_ip, mem.member_ip2, mem.last_login, mem.is_spammer,]]></add>
</operation>

Here it is updated for Elk:
Code: [Select]
		<operation>
<search position="before"><![CDATA[
mem.id_member, mem.member_name, mem.real_name, mem.email_address, mem.member_ip, mem.member_ip2, mem.last_login,
mem.posts, mem.is_activated, mem.date_registered, mem.id_group, mem.additional_groups, mg.group_name]]></search>
<add><![CDATA[, mem.is_spammer]]></add>
</operation>
https://github.com/Frenzie/elk-stop-spammer/blob/19cb36458059393ede9fa7635ec6c6a1526d84e4/install_2.xml#L54-L72

Given that this only affects admins and moderators I suppose adding a whole extra query wouldn't really matter, but still. :P

Re: Temporary hooks listing/documentation

Reply #36

Lists are somehow tricky.
There are hooks, but there is no direct way to change the queries, so it's basically always a "DIY-and-append-the-results".
It's sub-optimal for sure, but with the current tools that's the best we can do.

I guess, in 2.0, we could have each column of the list as an object allowed to define the tables to query, the fields to fetch, the transformations to apply, etc.
Bugs creator.
Features destroyer.
Template killer.

Re: Temporary hooks listing/documentation

Reply #37

Do you happen to know of an example somewhere? But for now I'll probably just stick with the source mod. :)

Re: Temporary hooks listing/documentation

Reply #38

No, at the moment I don't have any example handy, even though I think I did something like that at some point... no idea where and when. lol
Bugs creator.
Features destroyer.
Template killer.

Re: Temporary hooks listing/documentation

Reply #39

@emanuele How do you use integrate_manage_members exactly?

Code: [Select]
$subActions['check'] = array(
'controller' => new StopSpammer_controller(),
'function' => 'action_list',
'permission' => 'moderate_forum');

Code: [Select]
PHP Fatal error: Uncaught exception 'Error' with message 'Class 'StopSpammer_controller' not found' in /home/frans/www/public_html/elkarte-1.1/sources/addons/StopSpammer/StopSpammer_hooks.php:233

StopSpammer.controller.php is present in CONTROLLERDIR.

What I want to do is add two new actions, namely Check these members and Report these members. See screenshot for the old style imported from the SMF addon, but although adding the buttons themselves is no problem making them work requires source edits, which I'd like to avoid as much as possible.

Edit: hm, why does posting here result in me realizing I hadn't tried a simple
Code: [Select]
require_once(CONTROLLERDIR .'/StopSpammer.controller.php');
Although for integrate_actions that doesn't seem to be necessary.

Not quite there yet, but I think I probably got past my obstacle. :P

Re: Temporary hooks listing/documentation

Reply #40

Hm, I think I have to admit defeat in not understanding how this stuff works.

I can add things to maction by simply using a button instead of an input type=button:
Code: [Select]
<button name="maction" value="spammers_check" type="submit">checkcheck</button>

Code: [Select]
require_once(CONTROLLERDIR .'/StopSpammer.controller.php');

$subActions['spammers_check'] = array(
'controller' => new StopSpammer_controller(),
'function' => 'action_list',
'permission' => 'moderate_forum');

But clearly I've got this controller thing set up all wrong:

Code: [Select]
class StopSpammer_Controller extends ManageMembers_Controller
{
public function action_list()
{
global $txt, $scripturl, $context, $modSettings;
print_r($this->_req->post);
// Set the current sub action.
$context['sub_action'] = $this->_req->getPost('sa', 'strval', 'all');
//print_r($context['sub_action']);
// Are we performing a mass action?
if (isset($this->_req->post->spammers_checks) && !empty($this->_req->post->members))
$this->_multiMembersAction();
}

protected function _multiMembersAction()
{
global $txt, $user_info;

// @todo add a token too?
checkSession();

// Clean the input.
$members = array();
foreach ($this->_req->post->members as $value)
{
// Don't delete yourself, idiot.
if ($this->_req->post->maction === 'delete' && $value == $user_info['id'])
continue;

$members[] = (int) $value;
}
$members = array_filter($members);

// No members, nothing to do.
if (empty($members))
return;

// Are we performing a check or report?
if ($this->_req->post->maction == 'spammers_checks' || $this->_req->post->maction == 'spammers_report')
{
checkreportMembers($members, $this->_req->post->maction == 'spammers_report');
}


}
}

Re: Temporary hooks listing/documentation

Reply #41

Quote from: Frenzie –
Code: [Select]
PHP Fatal error: Uncaught exception 'Error' with message 'Class 'StopSpammer_controller' not found' in /home/frans/www/public_html/elkarte-1.1/sources/addons/StopSpammer/StopSpammer_hooks.php:233
StopSpammer.controller.php is present in CONTROLLERDIR.
Hook error says it is not found in sources addon folder, not in sources controller folder, right?

Re: Temporary hooks listing/documentation

Reply #42

You are quite right, but honestly I don't even really understand what I'm trying to modify. I mean, I know how I could affect what I want using source edits, but I don't really know what the stuff you can modify with integrate_manage_members does in the first place. I'll await @emanuele 's explanation. :)

Re: Temporary hooks listing/documentation

Reply #43

My advice this hook only as far as you know and understand. Others you can modify first. Convert to hook later.

I also don't know that much. I think I learn more through copy and paste and trial and error.

What I may remember is once @emanuele did say you have to check the output or something for each integration for you to know how to use it properly. I can't remember which post though.

Edited: I think I found it.

Quote from: emanuele – You are using "integrate_prepare_display_context", so, where is it called?
In Display.controller.php at:
https://github.com/elkarte/Elkarte/blob/e7e6d32ca24365a11dde18f936dc2ff86dd52dc7/sources/controllers/Display.controller.php#L1004
So, what are the two variables you have available?
$output and $message.
What do they contain?
First read:
https://github.com/elkarte/Elkarte/blob/e7e6d32ca24365a11dde18f936dc2ff86dd52dc7/sources/controllers/Display.controller.php#L955
https://github.com/elkarte/Elkarte/blob/d210298c7a53f0ed94ecd04b291f4ab0240528f6/sources/subs/Messages.subs.php#L605

And then, in your function can use:
Code: [Select]
print_r($output);
Well, for better reading experience:
Code: [Select]
echo '<pre>';
print_r($output);
echo '</pre>';
Last Edit: February 08, 2017, 08:43:40 am by ahrasis

Re: Temporary hooks listing/documentation

Reply #44

Well yeah, but those are regular hooks. They're simple and print_r tells you all you need to know. ;)