root/trunk/gregarius/admin/index.php

Revision 1670, 10.7 kB (checked in by mbonetti, 21 months ago)

removed some deprecated strings

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2###############################################################################
3# Gregarius - A PHP based RSS aggregator.
4# Copyright (C) 2003 - 2006 Marco Bonetti
5#
6###############################################################################
7# This program is free software and open source software; you can redistribute
8# it and/or modify it under the terms of the GNU General Public License as
9# published by the Free Software Foundation; either version 2 of the License,
10# or (at your option) any later version.
11#
12# This program 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.      See the GNU General Public License for
15# more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  or visit
20# http://www.gnu.org/licenses/gpl.html
21#
22###############################################################################
23# E-mail:          mbonetti at gmail dot com
24# Web page:        http://gregarius.net/
25#
26###############################################################################
27
28define ('RSS_FILE_LOCATION','/admin');
29define ('THEME_OVERRIDE','default');
30
31require_once('../init.php');
32require_once('../opml.php');
33require_once('ds.php');
34
35require_once('channels.php');
36require_once('items.php');
37require_once('folders.php');
38require_once('opml.php');
39require_once('config.php');
40require_once('dashboard.php');
41require_once('users.php');
42require_once('plugins.php');
43require_once('themes.php');
44require_once('tags.php');
45require_once('../cls/wrappers/toolkit.php');
46
47define ('CST_ADMIN_DOMAIN','domain');
48define ('CST_ADMIN_DOMAIN_NONE','none');
49define ('CST_ADMIN_DELETE_ACTION','delete');
50define ('CST_ADMIN_DEFAULT_ACTION','default');
51define ('CST_ADMIN_EDIT_ACTION','edit');
52define ('CST_ADMIN_MOVE_UP_ACTION','up');
53define ('CST_ADMIN_MOVE_DOWN_ACTION','down');
54define ('CST_ADMIN_SUBMIT_EDIT','submit_edit');
55define ('CST_ADMIN_VIEW','view');
56define ('CST_ADMIN_CONFIRMED','confirmed');
57define ('CST_ADMIN_PRUNE','prune');
58define ('CST_ADMIN_DOMAIN_SYSINFO','sysinfo');
59define ('CST_ADMIN_METAACTION','metaaction');
60
61define ('CST_ADMIN_DOMAIN_DASHBOARD','dashboard');
62define ('CST_ADMIN_DOMAIN_FOLDER','folders');
63define ('CST_ADMIN_DOMAIN_CHANNEL','feeds');
64define ('CST_ADMIN_DOMAIN_ITEM','items');
65define ('CST_ADMIN_DOMAIN_CONFIG','config');
66define ('CST_ADMIN_DOMAIN_OPML','opml');
67define ('CST_ADMIN_DOMAIN_PLUGINS','plugins');
68define ('CST_ADMIN_DOMAIN_PLUGIN_OPTIONS','plugin_options');
69define ('CST_ADMIN_DOMAIN_THEMES','themes');
70define ('CST_ADMIN_DOMAIN_THEME_OPTIONS','theme_options');
71define ('CST_ADMIN_DOMAIN_TAGS','tags');
72// OPML import target
73define ('CST_ADMIN_OPML_IMPORT_WIPE',1);
74define ('CST_ADMIN_OPML_IMPORT_FOLDER',2);
75define ('CST_ADMIN_OPML_IMPORT_MERGE',3);
76
77
78$auth=rss_user_check_user_level(RSS_USER_LEVEL_ADMIN);
79if (! $auth) {
80    // check whether the admin password has been set.
81    $sql = "select uname,password from " . getTable('users') . " where ulevel=99";
82    list($dummy, $__pw__) = rss_fetch_row(rss_query($sql));
83    if ($__pw__ == '') {
84        $admin_uname = null;
85        $admin_pass = null;
86        if (isset($_POST['username']) && isset($_POST['password'])) {
87            $admin_uname = $_POST['username'];
88            $admin_pass = $_POST['password'];
89        }
90        set_admin_pass($admin_uname,$admin_pass);
91    } else {
92        rss_login_form();
93      exit();
94    }
95}
96
97admin_header();
98admin_main($auth);
99admin_footer();
100
101
102///////////////////////////////////////////////////////////////////////////////////////////
103
104/**
105 * main function. checks for authorization and renders the
106 * required admin section.
107 */
108function admin_main($authorised) {
109    echo "\n<div id=\"channel_admin\" class=\"frame\">";
110    if ($authorised) {
111        admin_menu();
112        if (array_key_exists(CST_ADMIN_DOMAIN,$_REQUEST)) {
113            switch($_REQUEST[CST_ADMIN_DOMAIN]) {
114            case CST_ADMIN_DOMAIN_FOLDER:
115                    $show = folder_admin();
116                break;
117            case CST_ADMIN_DOMAIN_CHANNEL:
118                $show = channel_admin();
119                break;
120            case CST_ADMIN_DOMAIN_CONFIG:
121                $show = config_admin();
122                break;
123            case CST_ADMIN_DOMAIN_ITEM:
124                $show = item_admin();
125                break;
126            case CST_ADMIN_DOMAIN_PLUGINS:
127                $show = plugins_admin();
128                break;
129            case CST_ADMIN_DOMAIN_THEMES:
130                $show = themes_admin();
131                break;
132                        case CST_ADMIN_DOMAIN_TAGS:
133                                $show = tags_admin();
134                                break;
135            case CST_ADMIN_DOMAIN_PLUGIN_OPTIONS:
136                $show = plugin_options_admin();
137                break;
138            case CST_ADMIN_DOMAIN_THEME_OPTIONS:
139                $show = theme_options_admin();
140                break;
141            default:
142                break;
143            }
144        }
145
146        if (array_key_exists(CST_ADMIN_VIEW,$_REQUEST) || isset($show)) {
147            if (!isset($show)) {
148                $show = $_REQUEST[CST_ADMIN_VIEW];
149            }
150            switch ($show) {
151            case CST_ADMIN_DOMAIN_CONFIG:
152                config();
153                break;
154            case CST_ADMIN_DOMAIN_CHANNEL:
155                channels();
156                break;
157            case CST_ADMIN_DOMAIN_FOLDER:
158                folders();
159                break;
160            case CST_ADMIN_DOMAIN_OPML:
161                opml();
162                break;
163            case CST_ADMIN_DOMAIN_NONE:
164                break;
165            case CST_ADMIN_DOMAIN_ITEM:
166                items();
167                break;
168            case CST_ADMIN_DOMAIN_SYSINFO:
169                sysinfo();
170                break;
171            case CST_ADMIN_DOMAIN_DASHBOARD:
172                dashboard();
173                break;
174            case CST_ADMIN_DOMAIN_PLUGINS:
175                plugins();
176                break;
177            case CST_ADMIN_DOMAIN_THEMES:
178                themes();
179                break;
180                        case CST_ADMIN_DOMAIN_TAGS:
181                                tags();
182                                break;
183            case CST_ADMIN_DOMAIN_PLUGIN_OPTIONS:
184                plugin_options();
185                break;
186            case CST_ADMIN_DOMAIN_THEME_OPTIONS:
187                theme_options();
188                break;
189            default:
190            }
191        } else {
192            if(true == getConfig('rss.config.defaultdashboard')) {
193                dashboard();
194            } else {
195                channels();
196            }
197        }
198
199        echo "\n<div class=\"clearer\"></div>\n";
200
201    } else {
202        rss_error(sprintf(__('<h1>Not Authorized!</h1>You are not authorized to access the administration interface. Please follow <a href="%s">this link</a> back to the main page. Have  a nice day!'),getPath()), RSS_ERROR_ERROR,true);
203    }
204    echo "</div>\n";
205}
206
207/////////
208
209/**
210 * Renders the admin sub-menu
211 */
212function admin_menu() {
213    $active = array_key_exists(CST_ADMIN_VIEW, $_REQUEST) ? $_REQUEST[CST_ADMIN_VIEW] : null;
214    $use_mod_rewrite = false;
215
216    echo "\n<ul class=\"navlist\">\n";
217    foreach (array (
218                 /* url/id -- internationalized label, defined in intl/* */
219                 array (CST_ADMIN_DOMAIN_DASHBOARD, __('Dashboard')),
220                 array (CST_ADMIN_DOMAIN_CHANNEL, __('feeds')),
221                 array (CST_ADMIN_DOMAIN_ITEM, __('items')),
222                 array (CST_ADMIN_DOMAIN_CONFIG, __('config')),
223                 array (CST_ADMIN_DOMAIN_PLUGINS, __('plugins')),
224                 array (CST_ADMIN_DOMAIN_THEMES, __('themes')),
225                 array (CST_ADMIN_DOMAIN_FOLDER, __('folders')),
226                 array (CST_ADMIN_DOMAIN_OPML, __('opml')),
227                 array (CST_ADMIN_DOMAIN_TAGS, __('Tags'))) as $item) {
228
229        $link = "index.php?view=".$item[0];
230        $lbl = $item[1];
231        $cls = ($item[0] == $active ? " class=\"active\"" : "");
232        echo "\t<li$cls><a href=\"".getPath()."admin/$link\">".ucfirst($lbl)."</a></li>\n";
233    }
234    echo "\t<li><a href=\"".getPath()."?logout\">".__('Logout')."</a></li>\n";
235    echo "</ul>\n";
236}
237
238function admin_kses_to_html($arr) {
239    $ret = "";
240    foreach ($arr as $tag => $attr) {
241        $ret .= "&lt;$tag";
242        foreach ($attr as $nm => $val) {
243            $ret .= "&nbsp;$nm=\"...\"&nbsp;";
244        }
245        $ret .= "&gt;\n";
246    }
247    return $ret;
248}
249
250
251function getLanguages() {
252
253    $d = dir('../intl');
254    $files = array();
255    $ret = array();
256    $activeIdx = "0";
257        $ret['en_US']=array(
258                'language'=>'English',
259                'windows-locale'=>'english'
260        );
261    while (false !== ($entry = $d->read())) {
262        if (preg_match('#^[a-z]{2}_?([A-Z]{2})?$#',$entry)) {
263                $ret[$entry]=getLanguageInfo($entry);
264        } 
265    }
266    $d->close();
267    return $ret;
268}
269
270
271
272function getLanguageInfo($dir) {
273    $info = array();
274    $path = "../intl/$dir/langinfo.txt";
275    if (file_exists($path)) {
276        $f = @fopen($path,'r');
277        $contents = "";
278        if ($f) {
279            $contents .= fread($f, filesize($path));
280            @fclose($f);
281        } else {
282            $contents = "";
283        }
284
285        if ($contents && preg_match_all("/([^:]+):(.*)/",$contents,$matches,PREG_SET_ORDER)) {
286            foreach($matches as $match) {
287                $key = trim(strtolower($match[1]));
288                $val = trim($match[2]);
289                $info[$key] = $val;
290            }
291        }
292    }
293
294    return $info;
295}
296
297function admin_enum_to_html($arr) {
298    $idx = array_pop($arr);
299    $ret = "";
300    foreach ($arr as $i => $val) {
301        if ($i == $idx)
302            $ret .= "$val";
303    }
304    return $ret;
305}
306
307function admin_header() {
308
309    header('Content-Type: text/html; charset='
310           . (getConfig('rss.output.encoding') ? getConfig('rss.output.encoding') : DEFAULT_OUTPUT_ENCODING));
311    echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
312    echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n";
313    echo "<head>";
314
315    $header = new Header(admin_title(), LOCATION_ADMIN, null, '', (HDR_NONE | HDR_NO_CACHECONTROL | HDR_NO_OUPUTBUFFERING));
316    $header -> render();
317
318    echo "</head>";
319    echo "<body>\n";
320
321    echo ""
322    ."<div id=\"nav\" class=\"frame\">"
323    ."<h1 id=\"top\">" .rss_main_title() ."</h1>";
324    $nav = new Navigation();
325    $nav->render();
326    echo "</div>";
327}
328
329function admin_footer() {
330    echo "<div id=\"footer\" class=\"frame\">\n";
331    rss_main_footer();
332    echo "</div>\n\n</body>\n</html>\n";
333}
334
335function admin_title() {
336        $title = array(__("Admin"));
337    if (array_key_exists(CST_ADMIN_VIEW,$_REQUEST)) {
338        $title[] = ucwords(
339                preg_replace('#[^a-zA-Z]#',' ',$_REQUEST[CST_ADMIN_VIEW])
340        ) ;
341    }
342    return $title;
343}
344?>
Note: See TracBrowser for help on using the browser.