2012-12-10, 12:18 PM
Thanks again for all your advices and guidance. I've followed all your suggestions, I hope, except for the capitalization of SQL statement keywords (really, I can't stand all caps) and the CAPTCHA clean up interval (will talk about that later).
By the way, this is the code I use for task insertion, removal, enabling, and disabling right now. I tried to make the functions as general as possible.
@frostschutz:
Honestly, my original plan is let a CAPTCHA expire in 15 minutes. My plugin tries to be as strict as possible. (For example, the IP that requests for the CAPTCHA must be identical to the one which answers it.) If one leaves the page open for more than hour, I believe he should refresh it.
@euantor:
Thanks for your detailed guide on the translation part.
Awesome!
By the way, this is the code I use for task insertion, removal, enabling, and disabling right now. I tried to make the functions as general as possible.
function captchapack_install() {
// ...
captchapack_task_add(array(
"title" => 'CAPTCHA Pack Cleanup',
"description" => 'Clean up old CAPTCHA entries.',
"file" => 'captchapack',
"minute" => '0',
));
// ...
}
// ...
function captchapack_uninstall() {
// ...
captchapack_task_drop('captchapack', 'CAPTCHA Pack Cleanup');
}
// ...
function captchapack_activate() {
// ...
captchapack_task_enable('captchapack');
// ...
}
// ...
/**
* Add a task.
*
* Code stolen from MyBB itself.
*/
function captchapack_task_add($task) {
require_once MYBB_ROOT . 'inc/functions_task.php';
global $db, $cache;
// Merge default values
$task_def = array(
'title' => '',
'description' => '',
'file' => '',
'minute' => '*',
'hour' => '*',
'day' => '*',
'month' => '*',
'weekday' => '*',
'enabled' => 0,
'logging' => 1,
);
$task = array_merge($task_def, $task);
if (!$task['file'] || !$task['title'])
return false;
// If there's a task with the same title or filename, drop it
captchapack_task_drop($task['file'], $task['title']);
// Escape all the things in the task
$task = array(
'title' => $db->escape_string($task['title']),
'description' => $db->escape_string($task['description']),
'file' => $db->escape_string($task['file']),
'minute' => $db->escape_string($task['minute']),
'hour' => $db->escape_string($task['hour']),
'day' => $db->escape_string($task['day']),
'month' => $db->escape_string($task['month']),
'weekday' => $db->escape_string($task['weekday']),
'enabled' => (int) $task['enabled'],
'logging' => (int) $task['logging'],
);
// Fill nextrun
$task['nextrun'] = fetch_next_run($task);
// Insert, and update cache
$db->insert_query("tasks", $task);
$cache->update_tasks();
return true;
}
/**
* Drop a task.
*
* Code stolen from MyBB itself.
*/
function captchapack_task_drop($file, $title) {
global $db, $cache;
$file = $db->escape_string($file);
$title = $db->escape_string($title);
$db->delete_query('tasks', "file = '$file' or title = '$title'");
$cache->update_tasks();
}
/**
* Enable a task.
*
* Code stolen from MyBB itself.
*/
function captchapack_task_enable($file) {
global $db;
$file = $db->escape_string($file);
$db->update_query('tasks', array('enabled' => 1), "file = '$file'");
}
/**
* Disable a task.
*
* Code stolen from MyBB itself.
*/
function captchapack_task_disable($file) {
global $db;
$file = $db->escape_string($file);
$db->update_query('tasks', array('enabled' => 0), "file = '$file'");
}
@frostschutz:
(2012-12-09, 03:42 PM)frostschutz Wrote: While on the topic of tasks, I'd allow more than just one hour of time. People leave their tabs open and forget about them, so... you could make it a setting
Honestly, my original plan is let a CAPTCHA expire in 15 minutes. My plugin tries to be as strict as possible. (For example, the IP that requests for the CAPTCHA must be identical to the one which answers it.) If one leaves the page open for more than hour, I believe he should refresh it.
@euantor:
Thanks for your detailed guide on the translation part.
(2012-12-09, 03:50 PM)euantor Wrote: You are correct. The wiki needs some major work done on it. I'll likely modify the plugin page when I get time.
Awesome!