Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
831 florian 1
<?php
2
 
3
if(!defined("PHORUM_ADMIN")) return;
4
 
5
require_once("./include/admin/PhorumInputForm.php");
6
require_once("./mods/smileys/smileyslib.php");
7
require_once("./mods/smileys/defaults.php");
8
 
9
// The definition of the possible uses for a smiley.
10
$PHORUM_MOD_SMILEY_USES = array(
11
 
12
    1   => "Subject",
13
    2   => "Body + Subject",
14
);
15
 
16
// ---------------------------------------------------------------------------
17
// Handle actions for sent form data.
18
// ---------------------------------------------------------------------------
19
 
20
// The action to perform.
21
$action = isset($_POST["action"]) ? $_POST["action"] : "";
22
 
23
// Keep track if the settings must be saved in the database.
24
$do_db_update = false;
25
 
26
// Keep track of error and success messages.
27
$error="";
28
$okmsg = "";
29
 
30
// Initialize smiley_id parameter.
31
$smiley_id = isset($_POST["smiley_id"]) ?  $_POST["smiley_id"] : "NEW";
32
 
33
// ACTION: Changing the mod_smileys settings.
34
if (empty($error) && $action == "edit_settings") {
35
    $_POST["prefix"] = trim($_POST["prefix"]);
36
    // Is the field filled in?
37
    if (empty($_POST["prefix"])) {
38
        $error = "Please, fill in the smiley prefix path";
39
    // Deny absolute paths.
40
    } elseif (preg_match(MOD_SMILEYS_ABSPATH_MATCH, $_POST["prefix"])) {
41
        $error = "The smiley path must be a path, relative to Phorum's " .
42
                 "installation directory";
43
    // Is the specified prefix a directory?
44
    } elseif (!is_dir($_POST["prefix"])) {
45
        $error = "The smiley prefix path " .
46
                 '"' . htmlspecialchars($_POST["prefix"]) . '" ' .
47
                 " does not exist";
48
    }
49
 
50
    // All is okay. Set the prefix path in the config.
51
    if (empty($error))
52
    {
53
        // Make sure the prefix path ends with a "/".
54
        if (substr($_POST["prefix"], -1, 1) != '/') {
55
            $_POST["prefix"] .= "/";
56
        }
57
 
58
        $PHORUM["mod_smileys"]["prefix"] = $_POST["prefix"];
59
 
60
        $okmsg = "The smiley settings have been saved successfully";
61
        $do_db_update = true;
62
    }
63
}
64
 
65
// ACTION: Adding or updating smileys.
66
if (empty($error) && $action == "edit_smiley")
67
{
68
    // Trim whitespace from form input fields.
69
    foreach (array("search","smiley","alt") as $field) {
70
        if (isset($_POST[$field])) $_POST[$field] = trim($_POST[$field]);
71
    }
72
 
73
    // Check if the search string is entered.
74
    if (empty($_POST["search"]))
75
        $error = "Please enter the string to match";
76
    // Check if a replace smiley is selected.
77
    elseif (empty($_POST["smiley"]))
78
        $error = "Please, select a smiley to replace the string " .
79
                 htmlspecialchars($_POST["search"]) . " with";
80
    // Check if the smiley doesn't already exist.
81
    if (empty($error)) {
82
        foreach ($PHORUM["mod_smileys"]["smileys"] as $id => $smiley) {
83
            if ($smiley["search"] == $_POST["search"] &&
84
                $_POST["smiley_id"] != $id) {
85
                $error = "The smiley " .
86
                         '"' . htmlspecialchars($_POST["search"]) . '" ' .
87
                         "already exists";
88
                break;
89
            }
90
        }
91
    }
92
 
93
    // All fields are okay. Update the smiley list.
94
    if (empty($error))
95
    {
96
        $item = array(
97
            "search" => $_POST["search"],
98
            "smiley" => $_POST["smiley"],
99
            "alt"    => $_POST["alt"],
100
            "uses"   => $_POST['uses']
101
        );
102
 
103
        if ($smiley_id == "NEW") {
104
            $PHORUM["mod_smileys"]["smileys"][]=$item;
105
            $okmsg = "The smiley has been added successfully";
106
        } else {
107
            $PHORUM["mod_smileys"]["smileys"][$smiley_id]=$item;
108
            $okmsg = "The smiley has been updated successfully";
109
        }
110
 
111
        $do_db_update = true;
112
    }
113
}
114
 
115
// GET based actions.
116
if (empty($error) && isset($_GET["smiley_id"]))
117
{
118
    // ACTION: Deleting a smiley from the list.
119
    if (isset($_GET["delete"])) {
120
        unset($PHORUM["mod_smileys"]["smileys"][$_GET["smiley_id"]]);
121
        $do_db_update = true;
122
        $okmsg = "The smiley has been deleted successfully";
123
    }
124
 
125
    // ACTION: Startup editing a smiley from the list.
126
    if (isset($_GET["edit"])) {
127
        $smiley_id = $_GET["smiley_id"];
128
    }
129
}
130
 
131
 
132
// ---------------------------------------------------------------------------
133
// Do database updates.
134
// ---------------------------------------------------------------------------
135
 
136
// Changes have been made to the smileys configuration.
137
// Store these changes in the database.
138
if (empty($error) && $do_db_update)
139
{
140
    list($modinfo, $message) = phorum_mod_smileys_store($PHORUM["mod_smileys"]);
141
    if ($modinfo == NULL) {
142
        $error = $message;
143
    } else {
144
        if (empty($okmsg)) $okmsg = $message;
145
        $PHORUM["mod_smileys"] = $modinfo;
146
 
147
        // Back to the startscreen
148
        unset($_POST);
149
        $smiley_id = 'NEW';
150
    }
151
}
152
 
153
 
154
// ---------------------------------------------------------------------------
155
// Display the settings page
156
// ---------------------------------------------------------------------------
157
 
158
// Get the current list of available smiley images.
159
$available_smileys = phorum_mod_smileys_available();
160
 
161
// Javascript for displaying a smiley preview when a smiley image
162
// is selected from the drop down box.
163
?>
164
<script type="text/javascript">
165
function change_image(new_image) {
166
  var div = document.getElementById("preview_div");
167
  var img = document.getElementById("preview_image");
168
  if (new_image.length == 0) {
169
    new_image = "./images/trans.gif";
170
    div.style.display = 'none';
171
  } else {
172
    new_image = "<?php print $PHORUM["mod_smileys"]["prefix"]?>" + new_image;
173
    div.style.display = 'block';
174
  }
175
  img.src =new_image;
176
}
177
</script>
178
<?php
179
 
180
// Display the result message.
181
if (! empty($error)) {
182
    phorum_admin_error($error);
183
} elseif (! empty($okmsg)) {
184
    phorum_admin_okmsg($okmsg);
185
}
186
 
187
// Count things.
188
$total_smileys = 0;
189
$inactive_smileys = 0;
190
foreach ($PHORUM["mod_smileys"]["smileys"] as $id => $smiley) {
191
    $total_smileys ++;
192
    if (! $smiley["active"]) $inactive_smileys ++;
193
}
194
 
195
// Display a warning in case there are no smiley images available.
196
if (! count($available_smileys)) {
197
    phorum_admin_error(
198
        "<strong>Warning:</strong><br/>" .
199
        "No smiley images were found in your current smiley prefix " .
200
        "path. Please place some smileys in the directory " .
201
        htmlspecialchars($PHORUM["mod_smileys"]["prefix"]) .
202
        " or change your prefix path to point to a directory " .
203
        "containing smiley images.");
204
} elseif ($inactive_smileys) {
205
    phorum_admin_error(
206
        "<strong>Warning:</strong><br/>" .
207
        "You have $inactive_smileys smiley(s) configured for which the " .
208
        "image file was not found (marked as \"UNAVAILBLE\" in the list " .
209
        "below). Delete the smiley(s) from the list or place the missing " .
210
        "images in the directory \"" .
211
        htmlspecialchars($PHORUM["mod_smileys"]["prefix"]) . "\". After " .
212
        "placing new smiley images, click \"Save settings\" to update " .
213
        "the smiley settings.");
214
}
215
 
216
// Create the smiley settings form.
217
if ($smiley_id == "NEW")
218
{
219
    $frm = new PhorumInputForm ("", "post", 'Save settings');
220
    $frm->hidden("module", "modsettings");
221
    $frm->hidden("mod", "smileys");
222
    $frm->hidden("action", "edit_settings");
223
    $frm->addbreak("Smiley Settings");
224
    $row = $frm->addrow("Smiley Prefix Path", $frm->text_box("prefix", $PHORUM["mod_smileys"]["prefix"], 50));
225
    $frm->addhelp($row,
226
        "Set the smiley image prefix path",
227
        "This option can be used to set the path to the directory where
228
         you have stored your smileys. This path must be relative to the
229
         directory in which you installed the Phorum software. Absolute
230
         paths cannot be used here.");
231
    $frm->show();
232
}
233
 
234
// No smiley images in the current prefix path? Then do not show the
235
// rest of the forms. Let the admin fix this issue first.
236
if (!count($available_smileys)) return;
237
 
238
// Create the smiley adding and editing form.
239
if (isset($_POST["smiley_id"])) {
240
    $search = $_POST["search"];
241
    $smiley = $_POST["smiley"];
242
    $alt    = $_POST["alt"];
243
    $uses   = $_POST["uses"];
244
}
245
if ($smiley_id == "NEW") {
246
    $title = "Add a new smiley";
247
    $submit = "Add smiley";
248
 
249
    // Fill initial form data for creating smileys.
250
    if (! isset($_POST["smiley_id"])) {
251
        $search = "";
252
        $smiley = "";
253
        $alt    = "";
254
        $uses   = 2;
255
    }
256
} else {
257
    $title = "Update a smiley";
258
    $submit = "Update smiley";
259
 
260
    // Fill initial form data for editing smileys.
261
    if (! isset($_POST["smiley_id"])) {
262
        $smileydata = $PHORUM["mod_smileys"]["smileys"][$smiley_id];
263
        $search = $smileydata["search"];
264
        $smiley = $smileydata["smiley"];
265
        $alt    = $smileydata["alt"];
266
        $uses   = $smileydata["uses"];
267
    }
268
}
269
$frm = new PhorumInputForm ("", "post", $submit);
270
$frm->hidden("module", "modsettings");
271
$frm->hidden("mod", "smileys");
272
$frm->hidden("smiley_id", $smiley_id);
273
$frm->hidden("action", "edit_smiley");
274
$frm->addbreak($title);
275
$frm->addrow("Smiley string to match", $frm->text_box("search", $search, 20));
276
$row = $frm->addrow("Image to replace the string with", $frm->select_tag("smiley", array_merge(array(''=>'Select smiley ...'),$available_smileys), $smiley, "onChange=\"change_image(this.options[this.selectedIndex].value);\"") . "&nbsp;&nbsp;<div style=\"display:none;margin-top:5px\" id=\"preview_div\"><strong>Preview: </strong><img src=\"images/trans.gif\" id=\"preview_image\" /></div>");
277
$frm->addhelp($row,
278
    "Smiley replacement image",
279
    "The drop down list shows all images that were found in your
280
     smiley prefix path. If you want to add your own smileys, simply place
281
     them in \"" . htmlspecialchars($PHORUM["mod_smileys"]["prefix"]) . "\"
282
     and reload this page.");
283
$frm->addrow("ALT tag for the image", $frm->text_box("alt", $alt, 40));
284
$frm->addrow("Used for", $frm->select_tag("uses", $PHORUM_MOD_SMILEY_USES, $uses));
285
$frm->show();
286
 
287
// Make the preview image visible in case a $smiley is set.
288
if (!empty($smiley)) {?>
289
    <script type="text/javascript">
290
    change_image('<?php print addslashes($smiley) ?>');
291
    </script><?php
292
}
293
 
294
// Show the configured list of smileys.
295
if ($smiley_id == "NEW")
296
{
297
    print "<hr class=\"PhorumAdminHR\" />";
298
 
299
    if (count($PHORUM["mod_smileys"]["smileys"]))
300
    { ?>
301
        <table cellspacing="1" class="PhorumAdminTable" width="100%">
302
        <tr>
303
          <td class="PhorumAdminTableHead">String</td>
304
          <td class="PhorumAdminTableHead">Image file</td>
305
          <td class="PhorumAdminTableHead">Image</td>
306
          <td class="PhorumAdminTableHead">ALT tag</td>
307
          <td class="PhorumAdminTableHead">Used for</td>
308
          <td class="PhorumAdminTableHead">&nbsp;</td>
309
        </tr>
310
        <?php
311
 
312
        foreach ($PHORUM["mod_smileys"]["smileys"] as $id => $item)
313
        {
314
            $used_for_txt = $PHORUM_MOD_SMILEY_USES[$item['uses']];
315
            foreach ($item as $key => $val) {
316
                $item[$key] = htmlspecialchars($val);
317
            }
318
            $action_url = "$_SERVER[PHP_SELF]?module=modsettings&mod=smileys&smiley_id=$id";
319
 
320
            print "<tr>\n";
321
            print "  <td class=\"PhorumAdminTableRow\">{$item["search"]}</td>\n";
322
            print "  <td class=\"PhorumAdminTableRow\">{$item["smiley"]}</td>\n";
323
            print "  <td class=\"PhorumAdminTableRow\" align=\"center\">";
324
            if ($item["active"]) {
325
              print "<img src=\"{$PHORUM["mod_smileys"]["prefix"]}{$item["smiley"]}\"/></td>\n";
326
            } else {
327
              print "<div style=\"color:red\">UNAVAILBLE</div>";
328
            }
329
            print "  <td class=\"PhorumAdminTableRow\">{$item["alt"]}</td>\n";
330
            print "  <td class=\"PhorumAdminTableRow\" style=\"white-space:nowrap\">$used_for_txt</td>\n";
331
            print "  <td class=\"PhorumAdminTableRow\">" .
332
                  "<a href=\"$action_url&edit=1\">Edit</a>&nbsp;&#149;&nbsp;" .
333
                  "<a href=\"$action_url&delete=1\">Delete</a></td>\n";
334
            print "</tr>\n";
335
        }
336
 
337
        print "</table>\n";
338
 
339
    } else {
340
 
341
        print "Currently, you have no smiley replacements configured.";
342
 
343
    }
344
 
345
    // For a more clear end of page.
346
    print "<br/><br/><br/>";
347
}
348
 
349
?>