Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions forum/qa-plugin/send-pw-on-register/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "Auto-send register PW message.",
"uri": "https://github.com/CodersCommunity/forum.pasja-informatyki.local",
"description": "This plugin automatically send private message to new user.",
"version": "1.0",
"date": "2018-06-10",
"author": "Mariusz08",
"author_uri": "https://forum.pasja-informatyki.pl/user/Mariusz08",
"license": "GNU GPL v2",
"update_uri": "https://github.com/CodersCommunity/forum.pasja-informatyki.local",
"min_q2a": "1.7",
"min_php": "5.3"
}
32 changes: 32 additions & 0 deletions forum/qa-plugin/send-pw-on-register/qa-plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/*
Plugin Name: Auto-send register PW message.
Plugin URI: https://github.com/CodersCommunity/forum.pasja-informatyki.local
Plugin Description: This plugin automatically send private message to new user.
Plugin Version: 1.0
Plugin Date: 2018-06-10
Plugin Author: Mariusz08
Plugin Author URI: https://forum.pasja-informatyki.pl/user/Mariusz08
Plugin License: GNU GPL v2
Plugin Update Check URI: https://github.com/CodersCommunity/forum.pasja-informatyki.local
Plugin Minimum Question2Answer Version: 1.7
Plugin Minimum PHP Version: 5.3
*/

if (!defined('QA_VERSION')) {
header('Location: ../../');
exit;
}

qa_register_plugin_module(
'event',
'qa-pw-admin.php',
'qa_pw_admin',
'PW Admin'
);

qa_register_plugin_module(
'event',
'qa-pw-event.php',
'qa_pw_event',
'PW Event');
71 changes: 71 additions & 0 deletions forum/qa-plugin/send-pw-on-register/qa-pw-admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

class qa_pw_admin
{
public function admin_form(&$qa_content)
{
$isSaved = false;
$info = null;

if (qa_clicked('sendPwMessageOnRegister_save')) {
$canSave = (bool) qa_post_text('enablePlugin');
qa_opt('sendPwMessageOnRegister_messageContent', qa_post_text('messageContent'));

if (empty(qa_post_text('messageContent'))) {
$canSave = false;
$info['content'] = 'Empty message content';
}

require_once QA_INCLUDE_DIR . 'db/users.php';

if ([] === qa_db_user_get_userid_handles(qa_post_text('botId'))) {
$canSave = false;
$info['botId'] = 'Invalid bot id';
} else {
qa_opt('sendPwMessageOnRegister_botId', qa_post_text('botId'));
}

if ($canSave) {
qa_opt('sendPwMessageOnRegister_enabled', qa_post_text('enablePlugin'));
$isSaved = true;
}
}

return $this->prepareAdminForm($isSaved, $info);
}

private function prepareAdminForm($isSaved, $info)
{
return [
'ok' => $isSaved ? 'Settings saved' : '',
'fields' => [
[
'label' => 'Enable plugin',
'tags' => 'name="enablePlugin"',
'value' => qa_opt('sendPwMessageOnRegister_enabled'),
'type' => 'checkbox'
],
[
'label' => '<span style="color: red; font-weight: bold;">DANGER ZONE!</span> Bot for sending messages (id): <span style="color: red; font-weight: bold;">DANGER ZONE!</span>',
'tags' => 'name="botId" type="number"',
'value' => qa_opt('sendPwMessageOnRegister_botId'),
'error' => empty($info['botId']) ? '' : $info['botId']
],
[
'label' => 'Message content:',
'tags' => 'name="messageContent"',
'value' => qa_html(qa_opt('sendPwMessageOnRegister_messageContent')),
'type' => 'textarea',
'rows' => 20,
'error' => empty($info['content']) ? '' : $info['content']
]
],
'buttons' => [
[
'label' => 'Save Changes',
'tags' => 'name="sendPwMessageOnRegister_save"',
]
]
];
}
}
37 changes: 37 additions & 0 deletions forum/qa-plugin/send-pw-on-register/qa-pw-event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

class qa_pw_event
{
public function process_event($event, $userId, $handle, $cookieId, $params)
{
if (qa_opt('sendPwMessageOnRegister_enabled') && 'u_register' === $event) {
require_once QA_INCLUDE_DIR . 'db/messages.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'db/users.php';

$botId = qa_opt('sendPwMessageOnRegister_botId');
$messageContent = qa_opt('sendPwMessageOnRegister_messageContent');

if (empty($botId) || empty($messageContent) || [] === qa_db_user_get_userid_handles(qa_post_text('botId'))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

co to za dziwny twór?

return;
}

$messsageId = qa_db_message_create(
$botId,
$userId,
$messageContent,
'',
false
);

$fromUserHandle = qa_db_query_sub('SELECT `handle` FROM ^users WHERE `userid` = #', $botId);

qa_report_event('u_message', $botId, $fromUserHandle, qa_cookie_get(), [
'userid' => $userId,
'handle' => $handle,
'messageid' => (int) $messageId,
'message' => $messageContent
]);
}
}
}