<?php
/*
* This file is part of Trevorchan.
*
* Trevorchan is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* Trevorchan is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* Trevorchan; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* +------------------------------------------------------------------------------+
* Fortune Module
* +------------------------------------------------------------------------------+
* Give your posters some good luck (or bad).
* +------------------------------------------------------------------------------+
*/
/* Module initialization */
function fortune_init() {
global $hooks;
$hooks['posting'][] = 'fortune';
}
/* Is this module authorized to be used right now? */
function fortune_authorized($board) {
$boards_authorized = explode('|', module_setting_get('fortune', 'boards'));
if (in_array($board, $boards_authorized)) {
return true;
} else {
return false;
}
}
function fortune_info() {
$info = array();
$info['type']['board-specific'] = true;
return $info;
}
function fortune_settings() {
$settings = array();
}
function fortune_help() {
$output = 'Fortune: Give your posters some good luck (or bad).';
return $output;
}
function fortune_process_posting($post) {
if (substr($post['name'], 0, 8) == '#fortune' || substr($post['email'], 0, 8) == '#fortune') {
$post['message'] = fortune__get_fortune() . '<br><br>' . $post['message'];
if (substr($post['name'], 0, 8) == '#fortune') {
$post['name'] = '';
} elseif (substr($post['email'], 0, 8) == '#fortune') {
$post['email'] = '';
}
}
return $post;
}
function fortune__get_fortune() {
$fortunes = explode('|', module_setting_get('fortune', 'fortunes'));
$fortune_index = rand(0, (count($fortunes) - 1));
$fortune = $fortunes[$fortune_index];
return $fortune;
}
?>