source: trunk/content/plugins/sb_base/sb_base_settings.php @ 1375

Revision 1375, 5.2 KB checked in by nick_ramsay, 3 years ago (diff)

[Trunk] Hotaru 1.1.3 [Run upgrade script]

Line 
1<?php
2/**
3 *  SB Base Settings
4 *
5 * PHP version 5
6 *
7 * LICENSE: Hotaru CMS is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * Hotaru CMS is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with Hotaru CMS. If not, see http://www.gnu.org/licenses/.
18 *
19 * @category  Content Management System
20 * @package   HotaruCMS
21 * @author    Nick Ramsay <admin@hotarucms.org>
22 * @copyright Copyright (c) 2009, Hotaru CMS
23 * @license   http://www.gnu.org/copyleft/gpl.html GNU General Public License
24 * @link      http://www.hotarucms.org/
25 */
26
27class SbBaseSettings
28{
29     /**
30     * Admin settings for the Submit plugin
31     */
32    public function settings($h)
33    {
34        // If the form has been submitted, go and save the data...
35        if ($h->cage->post->getAlpha('submitted') == 'true') {
36            $this->saveSettings($h);
37        }   
38       
39        echo "<h1>" . $h->lang["sb_base_settings_header"] . "</h1>\n";
40       
41        $h->showMessage(); // Saved / Error message
42       
43        // Get settings from database if they exist...
44        $sb_base_settings = $h->getSerializedSettings();
45       
46        $posts_per_page = $sb_base_settings['posts_per_page'];
47        $rss_redirect = $sb_base_settings['rss_redirect'];
48        $archive = $sb_base_settings['archive'];
49   
50        $h->pluginHook('sb_base_settings_get_values');
51       
52        //...otherwise set to blank:
53        if (!$posts_per_page) { $posts_per_page = 10; }
54        if (!$rss_redirect) { $rss_redirect = ''; }
55        if (!$archive) { $archive = 'no_archive'; }
56       
57        echo "<form name='sb_base_settings_form' action='" . BASEURL . "admin_index.php?page=plugin_settings&amp;plugin=sb_base' method='post'>\n";
58
59        // posts per page
60        echo "<p><input type='text' size=5 name='posts_per_page' value='" . $posts_per_page . "' /> ";
61        echo $h->lang["sb_base_settings_posts_per_page"] . "</p>\n";
62
63        // rss redirecting?
64        echo "<p><input type='checkbox' name='rss_redirect' value='rss_redirect' " . $rss_redirect . " >&nbsp;&nbsp;" . $h->lang["sb_base_settings_rss_redirect"] . "<br />\n";
65   
66        $h->pluginHook('sb_base_settings_form');
67   
68        echo "<br />\n";
69
70        // post archiving
71        echo $h->lang["sb_base_settings_post_archiving"] . "<br /><br />\n";
72        echo $h->lang["sb_base_settings_post_archive_desc"] . "<br /><br />\n";
73        echo "<select name='post_archive'>\n";
74            echo "<option value='" . $archive . "'>" . $h->lang["sb_base_settings_post_archive_$archive"] . "</option>\n";
75            echo '<option disabled>-----</option>';
76            echo "<option value='no_archive'>" . $h->lang["sb_base_settings_post_archive_no_archive"] . "</option>\n";
77            echo "<option value='180'>" . $h->lang["sb_base_settings_post_archive_180"] . "</option>\n";
78            echo "<option value='365'>" . $h->lang["sb_base_settings_post_archive_365"] . "</option>\n";
79            echo "<option value='730'>" . $h->lang["sb_base_settings_post_archive_730"] . "</option>\n";
80            echo "<option value='1095'>" . $h->lang["sb_base_settings_post_archive_1095"] . "</option>\n";
81        echo "</select>\n";
82        echo $h->lang["sb_base_settings_post_archive"] . "<br /><br />\n";
83
84        echo "<input type='hidden' name='submitted' value='true' />\n";
85        echo "<input type='submit' value='" . $h->lang["main_form_save"] . "' />\n";
86        echo "<input type='hidden' name='csrf' value='" . $h->csrfToken . "' />\n";
87        echo "</form>\n";
88    }
89   
90   
91    /**
92     * Save Submit Settings
93     */
94    public function saveSettings($h)
95    {
96        // Get current settings
97        $sb_base_settings = $h->getSerializedSettings();
98       
99        // Posts per page
100        $posts_per_page = $h->cage->post->testInt('posts_per_page');
101        if (!$posts_per_page) {
102            $posts_per_page = $sb_base_settings['posts_per_page'];
103        }
104       
105   
106        // RSS Redirecting
107        if ($h->cage->post->keyExists('rss_redirect')) {
108            $rss_redirect = 'checked';
109        } else {
110            $rss_redirect = '';
111        }
112   
113        // Post Archiving
114        $archive = $h->cage->post->testAlnumLines('post_archive');
115        if (!$archive) {
116            $archive = $sb_base_settings['archive'];
117        }
118       
119        $h->pluginHook('sb_base_save_settings');
120       
121        $sb_base_settings['posts_per_page'] = $posts_per_page;
122        $sb_base_settings['rss_redirect'] = $rss_redirect;
123        $sb_base_settings['archive'] = $archive;
124   
125        $h->updateSetting('sb_base_settings', serialize($sb_base_settings));
126       
127        $h->message = $h->lang["main_settings_saved"];
128        $h->messageType = "green";
129       
130        return true;   
131    }
132   
133}
134?>
Note: See TracBrowser for help on using the repository browser.