Only grab comments marked i18n to the template.
[squirrelmail.git] / plugins / fortune / functions.php
CommitLineData
28e62e6d 1<?php
4b4abf93 2
28e62e6d 3/**
4 * Fortune plugin functions
5 *
4b5049de 6 * @copyright &copy; 2004-2007 The SquirrelMail Project Team
28e62e6d 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
8 * @version $Id$
9 * @package plugins
10 * @subpackage fortune
11 */
12
13/**
c3806a9d 14 * Declare configuration global and set default value
28e62e6d 15 */
c3806a9d 16global $fortune_command;
17$fortune_command = '/usr/games/fortune -s';
28e62e6d 18
19/**
20 * Load site config
21 */
22if (file_exists(SM_PATH . 'config/fortune_config.php')) {
23 include_once(SM_PATH . 'config/fortune_config.php');
24} elseif (file_exists(SM_PATH . 'plugins/fortune/config.php')) {
25 include_once(SM_PATH . 'plugins/fortune/config.php');
26}
27
28/**
29 * Show fortune
30 * @access private
31 * @since 1.5.1
32 */
33function fortune_function() {
b1870063 34 global $oTemplate, $fortune_visible, $color, $fortune_command;
28e62e6d 35
36 if (!$fortune_visible) {
37 return;
38 }
39
c3806a9d 40 /* open handle and get all command output*/
41 $handle = popen($fortune_command,'r');
42 $fortune = '';
43 while ($read = fread($handle,1024)) {
44 $fortune .= $read;
28e62e6d 45 }
c3806a9d 46 /* if pclose return != 0, popen command failed. Yes, I know that it is broken when --enable-sigchild is used */
47 if (pclose($handle)) {
b986936a 48 // i18n: %s shows executed fortune cookie command.
c3806a9d 49 $fortune = sprintf(_("Unable to execute \"%s\"."),$fortune_command);
50 }
28e62e6d 51
b1870063 52 $oTemplate->assign('color', $color);
53 $oTemplate->assign('fortune', htmlspecialchars($fortune));
54 $output = $oTemplate->fetch('plugins/fortune/mailbox_index_before.tpl');
55 return array('mailbox_index_before' => $output);
56
28e62e6d 57}
58
59/**
60 * Add fortune options
61 * @access private
62 * @since 1.5.1
63 */
64function fortune_function_options() {
65 global $optpage_data;
66
67 $optpage_data['grps']['fortune'] = _("Fortunes:");
68 $optionValues = array();
69 $optionValues[] = array('name' => 'fortune_visible',
70 'caption' => _("Show fortunes at top of mailbox"),
71 'type' => SMOPT_TYPE_BOOLEAN,
72 'initial_value' => false );
73 $optpage_data['vals']['fortune'] = $optionValues;
74}
75
76/**
77 * Get fortune prefs
78 * @access private
79 * @since 1.5.1
80 */
81function fortune_function_load() {
82 global $username, $data_dir, $fortune_visible;
83
84 $fortune_visible = getPref($data_dir, $username, 'fortune_visible');
85}