root/branches/multiuser/schema.php

Revision 1759, 36.3 kB (checked in by mdodoo, 2 years ago)

Lots of things are still not working, but I think this code is better than what was currently committed ([1639]
should have been reverted, and the person who committed should have had their SVN access pulled, for example).
Created this by grabbing the trunk code and then manually inserting the MU branch's changes in. This is probably
not usable in an actual installation (no support for creating new user accounts yet, for example), but patches are
welcome.

Not sure why I write so much here - I am not sure anyone other than my fellow devs actually read them...

  • Property svn:eol-style set to native
  • Property svn:eolstyle 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('DBSTRUCT', dirname(__FILE__) . '/dbstruct.sql');
29
30require_once('util.php');
31require_once('cls/user.php');
32require_once('cls/l10n.php');
33
34/**
35 * Checks the db schema for the for all required tables, adds those which are missing.
36 * Returns the number of added tables;
37 */ 
38function checkSchema() {
39       
40        $missing_tables = array();
41        $actual_tables=array();
42        $expected_tables = getExpectedTables();
43       
44        $rs = rss_query( "show tables", true, true );
45        while(list($tbl) = rss_fetch_row($rs)) {
46                $actual_tables[]=$tbl;
47        }
48       
49        foreach ($expected_tables as $base => $tbl) {
50                $exists = array_search($tbl,$actual_tables);
51                if ($exists === FALSE || $exists === NULL) {
52                        $missing_tables[]=$base;
53                }
54        }
55       
56        $updated  = 0;
57        if (count($missing_tables) > 0) {
58                $msg = (count($actual_tables)?"Updating":"Creating")
59                        .' your database schema! This should be a one-time operation,'
60                        .' if you see this message over and over again please import your database schema'
61                        .' manually.';
62                rss_error($msg, RSS_ERROR_WARNING);
63
64                foreach($missing_tables as $table) {
65                        $updated += call_user_func("_init_$table"); 
66                }
67               
68                if ($updated == count($missing_tables)) {
69                        rss_error(__("Successfully created $updated of $updated database tables!"), RSS_ERROR_NOTICE);
70                } else {
71                        rss_error(
72                                (count($missing_tables) - $updated) . " out of "
73                        . count($missing_tables) ." tables could not be created!",RSS_ERROR_ERROR);
74                }
75        }
76       
77        if ($updated) {
78                rss_invalidate_cache();
79        }
80        return $updated;
81}
82
83function getExpectedTables() {
84$expected_tables = array (
85                "channels" => trim(getTable("channels")),
86                "config" => trim(getTable("config")),
87                "folders" => trim(getTable("folders")),
88                "item" => trim(getTable("item")),
89                "metatag" => trim(getTable("metatag")),
90                "tag" => trim(getTable("tag")),
91                "rating" => trim(getTable("rating")),
92                "cache" => trim(getTable("cache")),
93                "users" => trim(getTable("users")),
94                "dashboard" => trim(getTable("dashboard")),
95                "properties" => trim(getTable("properties")),
96                "channels2user" => trim(getTable("channels2user")),
97                "item2user" => trim(getTable("item2user"))
98        );
99        return $expected_tables;
100}
101
102function rss_query_wrapper($query, $dieOnError=true, $preventRecursion=false) {
103        global $out;
104
105        if (defined('DUMP_SCHEMA')) {
106                $out .= $query . ";\n";
107        } else {
108            rss_query(trim($query),$dieOnError,$preventRecursion);
109        }
110}
111
112/**
113 * this function handles specific schema updates that occurred
114 * during version updates.
115 *
116 * @return the number of updated tables
117 */
118function checkSchemaColumns($column) {
119        $updated = 0;
120        switch($column) {
121                case 'c.mode':
122                case 'mode':
123                        // default feed mode, added in 0.4.1
124                        rss_query('alter table ' .getTable('channels') .' add column mode int(16) not null default 1');
125                        if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
126                                $updated++;
127                                rss_error("updated schema for table " . getTable('channels'), RSS_ERROR_NOTICE);
128                        } else {
129                                rss_error("Failed updating schema for table " . getTable('channels')
130                                .": " . rss_sql_error_message(), RSS_ERROR_ERROR
131                                );
132                        }
133                break;
134                case 'c.itemsincache':
135                case 'itemsincache':
136                        // date feed was last refreshed, added in 0.5.3
137                        rss_query('alter table ' .getTable('channels') .' add column itemsincache text null');
138                        if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
139                                $updated++;
140                                rss_error("updated schema for table " . getTable('channels'), RSS_ERROR_NOTICE);
141                        } else {
142                                rss_error("Failed updating schema for table " . getTable('channels')
143                                .": " . rss_sql_error_message(), RSS_ERROR_ERROR
144                                );
145                        }
146                break;
147                case 'c.daterefreshed':
148                case 'daterefreshed':
149                        // date feed was last refreshed, added in 0.5.3
150                        rss_query('alter table ' .getTable('channels') .' add column daterefreshed datetime null default 1');
151                        if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
152                                $updated++;
153                                rss_error("updated schema for table " . getTable('channels'), RSS_ERROR_NOTICE);
154                        } else {
155                                rss_error("Failed updating schema for table " . getTable('channels')
156                                .": " . rss_sql_error_message(), RSS_ERROR_ERROR
157                                );
158                        }
159                // break; - fallthrough allowed on purpose because these are added at the same time
160                case 'c.refreshinterval':
161                case 'refreshinterval':
162                        // refresh interval of a feed (in minutes), added in 0.5.3
163                        rss_query('alter table ' .getTable('channels') .' add column refreshinterval int(16) not null default 60');
164                        if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
165                                $updated++;
166                                rss_error("updated schema for table " . getTable('channels'), RSS_ERROR_NOTICE);
167                        } else {
168                                rss_error("Failed updating schema for table " . getTable('channels')
169                                .": " . rss_sql_error_message(), RSS_ERROR_ERROR
170                                );
171                        }
172                // break; - fallthrough allowed on purpose because these are added at the same time
173                case 'c.etag':
174                case 'etag':
175                        // etag of the feed, (from HTTP header) added in 0.5.3
176                        rss_query('alter table ' .getTable('channels') .' add column etag varchar(255) default null');
177                        if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
178                                $updated++;
179                                rss_error("updated schema for table " . getTable('channels'), RSS_ERROR_NOTICE);
180                        } else {
181                                rss_error("Failed updating schema for table " . getTable('channels')
182                                .": " . rss_sql_error_message(), RSS_ERROR_ERROR
183                                );
184                        }
185                // break; - fallthrough allowed on purpose because these are added at the same time
186                case 'c.lastmodified':
187                case 'lastmodified':
188                        // last modified code returned by the feed (from HTTP header), added in 0.5.3
189                        rss_query('alter table ' .getTable('channels') .' add column lastmodified varchar(255) default null');
190                        if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
191                                $updated++;
192                                rss_error("updated schema for table " . getTable('channels'), RSS_ERROR_NOTICE);
193                        } else {
194                                rss_error("Failed updating schema for table " . getTable('channels')
195                                .": " . rss_sql_error_message(), RSS_ERROR_ERROR
196                                );
197                        }
198                break;
199                case 'i.author':
200                case 'author':
201                        // item's author
202                        rss_query('alter table ' . getTable('item') . ' add column author varchar(255) null');
203                        if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
204                                $updated++;
205                                rss_error('updated schema for table ' . getTable('item'), RSS_ERROR_NOTICE);
206                        } else {
207                                rss_error('Failed updating schema for table ' . getTable('item') . ': '
208                                        . rss_sql_error_message(), RSS_ERROR_ERROR);
209                        }
210                break;
211               
212                case 'm.tdate':
213                case 'tdate':
214                        // tag date
215                        rss_query('alter table ' . getTable('metatag') . ' add column tdate datetime null');
216                        if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
217                rss_query('update ' . getTable('metatag') . ' set tdate=now()');
218                                $updated++;
219                                rss_error('updated schema for table ' . getTable('metatag'), RSS_ERROR_NOTICE);
220                        } else {
221                                rss_error('Failed updating schema for table ' . getTable('metatag') . ': '
222                                        . rss_sql_error_message(), RSS_ERROR_ERROR);
223                        }
224                break;
225                case 'i.enclosure':
226                case 'enclosure':
227                        // enclosure for an item
228                        rss_query('alter table ' . getTable('item') . ' add column enclosure varchar(255) null');
229                        if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
230                                $updated++;
231                                rss_error('updated schema for table ' . getTable('item'), RSS_ERROR_NOTICE);
232                        } else {
233                                rss_error('Failed updating schema for table ' . getTable('item') . ': '
234                                        . rss_sql_error_message(), RSS_ERROR_ERROR);
235                        }
236                break;
237               
238                case 'userips':
239                case 'i.userips':
240                // users.userips: list of valid IP subnets the user has logged in from
241                rss_query('alter table ' . getTable('users') . ' add column userips text default \'\'');
242                        if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
243                                $updated++;
244                                rss_error('updated schema for table ' . getTable('users'), RSS_ERROR_NOTICE);
245                        } else {
246                                rss_error('Failed updating schema for table ' . getTable('users') . ': '
247                                        . rss_sql_error_message(), RSS_ERROR_ERROR);
248                        }
249                break;
250               
251               
252                case 'i.md5sum':
253                case 'md5sum':
254                        // md5check on an item - added in 0.5.3
255                        rss_query('alter table ' . getTable('item') . ' add column md5sum varchar(32) null');
256                        if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
257                                $updated++;
258                                rss_error('updated schema for table ' . getTable('item'), RSS_ERROR_NOTICE);
259                        } else {
260                                rss_error('Failed updating schema for table ' . getTable('item') . ': '
261                                        . rss_sql_error_message(), RSS_ERROR_ERROR);
262                        }
263                // break; - fallthrough allowed on purpose because these are added at the same time
264                case 'i.guid':
265                case 'guid':
266                        // guid of an item - added in 0.5.3
267                        rss_query('alter table ' . getTable('item') . ' add column guid text null');
268                        rss_query('alter table ' . getTable('item') . ' add index `guid` (`guid`(10))');
269                        if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
270                                $updated++;
271                                rss_error('updated schema for table ' . getTable('item'), RSS_ERROR_NOTICE);
272                        } else {
273                                rss_error('Failed updating schema for table ' . getTable('item') . ': '
274                                        . rss_sql_error_message(), RSS_ERROR_ERROR);
275                        }
276                case 'm.fkuid':
277                        // userid on metatags - added in 0.5.5
278                        rss_query('alter table ' . getTable('metatag') . ' add column fkuid bigint(15) not null');
279                        rss_query('alter table ' . getTable('metatag') . " add index 'fkuid' ('fkuid')");
280                        if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
281                                $updated++;
282                                rss_error('updated schema for table ' . getTable('metatag'), RSS_ERROR_NOTICE);
283                        } else {
284                                rss_error('Failed updating schema for table ' . getTable('metatag') . ': '
285                                 . rss_sql_error_message(), RSS_ERROR_ERROR);
286                        }
287                        break;
288                break;
289                case 'm.fkuid':
290                       // userid on metatags - added in 0.5.5
291                       rss_query('alter table ' . getTable('metatag') . ' add column fkuid bigint(15) not null');
292                       rss_query('alter table ' . getTable('metatag') . " add index 'fkuid' ('fkuid')");
293                       if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
294                               $updated++;
295                               rss_error('updated schema for table ' . getTable('metatag'), RSS_ERROR_NOTICE);
296                       } else {
297                               rss_error('Failed updating schema for table ' . getTable('metatag') . ': '
298                                       . rss_sql_error_message(), RSS_ERROR_ERROR);
299                       }
300               
301               break;
302        }
303        return $updated;
304}
305
306///////////////////////////////////////////////////////////////////////////////
307///////////////////////////////////////////////////////////////////////////////
308
309function _init_channels() {
310        $table = getTable('channels');
311        rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true);
312        $sql_create = str_replace('__table__',$table, <<< _SQL_
313                CREATE TABLE __table__ (
314                        id bigint(11) NOT NULL auto_increment,
315                        title varchar(255) NOT NULL default '',
316                        url varchar(255) NOT NULL default '',
317                        siteurl varchar(255) default NULL,
318                        parent tinyint(4) default '0',
319                        descr varchar(255) default NULL,
320                        dateadded datetime default NULL,
321                        daterefreshed datetime default NULL,
322                        refreshinterval int(16) NOT NULL default '60',
323                        itemsincache text default NULL,
324                        etag varchar(255) default NULL,
325                        lastmodified varchar(255) default NULL,
326                        icon varchar(255) default NULL,
327                        position int(11) NOT NULL default '0',
328                        mode int(16) NOT NULL default '1',
329                        PRIMARY KEY  (id),
330                        KEY url (url)
331                ) TYPE=MyISAM;   
332_SQL_
333);
334
335        rss_query_wrapper($sql_create, false, true);
336        if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
337                rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR);
338                return 0;
339        } else {
340                return 1;
341        }
342}
343///////////////////////////////////////////////////////////////////////////////
344
345function _init_dashboard() {
346        $table = getTable('dashboard');
347        rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true);
348        $sql_create = str_replace('__table__',$table, <<< _SQL_
349                CREATE TABLE __table__ (
350                        id bigint(11) NOT NULL auto_increment,
351                        title text NOT NULL default '',
352                        url text NOT NULL default '',
353                        position tinyint(1) NOT NULL default 0,
354                        obj text not NULL default '',
355                        daterefreshed datetime default NULL,
356                        itemcount tinyint(1) NOT NULL default 3,
357                        PRIMARY KEY  (id)
358                ) TYPE=MyISAM;   
359_SQL_
360);
361
362        rss_query_wrapper($sql_create, false, true);
363        if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
364                rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR);
365                return 0;
366        }
367       
368       
369        $baseData = array(
370                array ('Latest Gregarius News','http://devlog.gregarius.net/feed/?db=',0, 3),
371                array ('Latest Plugins','http://plugins.gregarius.net/rss.php?db=',1, 5),
372                array ('Latest Themes','http://themes.gregarius.net/rss.php?db=',1, 5),
373                array ('Latest Forum posts','http://forums.gregarius.net/feeds/?Type=rss2&db=',1, 5),
374//              array ('Technorati','http://www.technorati.com/watchlists/rss.html?wid=59610&db=',1, 5)
375        );
376
377        foreach ($baseData as $feed) {
378                list($title,$url,$pos, $cnt) = $feed;
379                rss_query_wrapper (
380                        "INSERT INTO $table (title, url, position, obj, daterefreshed, itemcount) VALUES "
381                        ." ('$title', '$url', '$pos', '', null, $cnt)"  , false, true); 
382                if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
383                        rss_error('The '  . $table .  ' table was created successfully, but I couldn\'t insert the default values. Please do so manually!', RSS_ERROR_ERROR);
384                        return 0;
385                }       
386        }
387       
388        return 1;
389       
390       
391}
392
393
394///////////////////////////////////////////////////////////////////////////////
395
396function _init_folders() {
397        $table = getTable('folders');
398        rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true);
399        $sql_create = str_replace('__table__',$table, <<< _SQL_
400                CREATE TABLE __table__ (
401                  id tinyint(11) NOT NULL auto_increment,
402                  name varchar(127) NOT NULL default '',
403                  position int(11) NOT NULL default '0',   
404                  PRIMARY KEY  (id),
405                  UNIQUE KEY name (name)
406                ) TYPE=MyISAM;   
407_SQL_
408);
409
410        rss_query_wrapper($sql_create, false, true);
411        if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
412                rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR);
413                return 0;
414        }
415       
416       
417        rss_query_wrapper ("INSERT INTO $table (id,name) VALUES (0,'')", false, true);
418        if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
419                rss_error('The '  . $table .  ' table was created successfully, but I couldn\'t insert the default values. Please do so manually!', RSS_ERROR_ERROR);
420                return 0;
421        }
422        rss_query_wrapper ("update $table set id=0 where id=1", false, true);
423        if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
424                rss_error('The '  . $table .  ' table was created successfully, but I couldn\'t insert the default values. Please do so manually!', RSS_ERROR_ERROR);
425                return 0;
426        }
427
428        return 1;
429}
430
431///////////////////////////////////////////////////////////////////////////////
432
433/** Config table */
434function _init_config() {
435        $cfg_table = getTable('config');
436       
437        rss_query_wrapper ('DROP TABLE IF EXISTS ' . $cfg_table, true, true);
438       
439        $sql_create = str_replace('__config__',$cfg_table, <<< _SQL_
440                CREATE TABLE __config__ (
441                             key_ varchar(127) NOT NULL default '',
442                             value_ text NOT NULL,
443                             default_ text NOT NULL,
444                             type_ enum('string','num','boolean','array','enum') NOT NULL default 'string',
445                             desc_ text,
446                             export_ varchar(127) default NULL,
447                             PRIMARY KEY  (key_)
448                             ) TYPE=MyISAM;
449_SQL_
450);
451
452        rss_query_wrapper($sql_create, false, true);
453        if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
454                rss_error('The ' .getTable('config') . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR);
455                return 0;
456        }
457
458       
459        return (setDefaults(null)?1:0);
460}
461
462
463function setDefaults($key) {
464        rss_error('inserting some default config values...', RSS_ERROR_NOTICE);
465        $defaults = array (
466                "rss.output.encoding"           =>              array("UTF-8","UTF-8","string","Output encoding for the PHP XML parser.","MAGPIE_OUTPUT_ENCODING"),
467                "rss.output.itemsinchannelview"=>array("10","10","num","Number of read items shown on for a single channel.",NULL),
468                "rss.output.showfavicons"       =>              array("true","true","boolean","Display the favicon for the channels that have one. Due to a IE bug, some icons do not render correctly. You can either change the URL to the icon in the admin screen, or turn the display of favicons off globally here.",NULL),
469                "rss.output.usemodrewrite"      =>              array("true","true","boolean","Make use of apache's mod_rewrite module to return sexy urls. Turn this off if your host doesn't allow you to change this apache setting.",NULL),
470                "rss.config.dateformat"         =>              array("F jS, Y, g:ia T","F jS, Y, g:ia T","string","Format to use when displaying dates. See here for help on the format: http://php.net/date Note that direct access to a given feed's month and day archives more or less depends on the fact that this date format contains the  \"F\" (Month) and \"jS\" (day) elements in this form. So feel free to change the order of the elements, but better leave those two tokens in :)",NULL),
471                "rss.meta.debug"                        =>              array("false","false","boolean"," When in debug mode some extra debug info is shown and the error reporting is a bit more verbose.",NULL),
472                "rss.output.compression"        =>              array("true","true","boolean","This variable turns output compression on and off. Output compression is handled by most browsers.",NULL),
473                "rss.output.channelcollapse"=>  array("true","true","boolean","Allow collapsing of channels on the main page. ",NULL),
474                "rss.output.channelcollapsedefault"=>   array("false","false","boolean","Collapse the channels on the main page by default",NULL),
475                "rss.output.usepermalinks"      =>              array("true","true","boolean","Display a permalink icon and allow linking a given item directly.",NULL),
476                "rss.config.markreadonupdate"=> array("false","false","boolean","Mark all old unread feeds as read when updating if new unread feeds are found.",NULL),
477                "rss.output.lang"                       =>              array("en_US,zh_CN,de,da,es,fr,he,it,ja,pt_BR,pt,ru,sv,0","en_US,zh_CN,de,da,es,fr,he,it,ja,pt_BR,pt,ru,sv,0","enum","Language pack to use.",NULL),
478                "rss.config.absoluteordering"=> array("true","true","boolean","Allow feeds and folders to be ordered by their order in the admin section. If this option is set to false, channels and folders will be organized alphabetically by their titles.",NULL),
479                "rss.config.robotsmeta"         =>              array("noindex,follow","noindex,follow","string","How should spiders crawl us? (see http://www.robotstxt.org/wc/meta-user.html for more info).",NULL),
480                "rss.config.serverpush"         =>              array("true","true","boolean","Use the server push method when updating your feeds in the browser. The browsers that support this (Mozilla and Opera) will be autodetected. Turn this option off if you do not use one of these browsers or if you would like to use the Ajax update method",NULL),
481                "rss.config.refreshafter"       =>              array("45","45","num","If this option is set the feeds will be updated after keeping the browser open for x minutes. Please respect the feed providers by not setting this value to anything lower than thirty minutes. Set this variable to 0 turn this option off.",NULL),
482                "rss.input.allowed"                     =>              array('a:21:{s:1:"a";a:2:{s:4:"href";i:1;s:5:"title";i:1;}s:1:"b";a:0:{}s:10:"blockquote";a:0:{}s:2:"br";a:0:{}s:4:"code";a:0:{}s:3:"del";a:0:{}s:2:"em";a:0:{}s:1:"i";a:0:{}s:3:"img";a:2:{s:3:"src";i:1;s:3:"alt";i:1;}s:3:"ins";a:0:{}s:2:"li";a:0:{}s:2:"ol";a:0:{}s:1:"p";a:0:{}s:3:"pre";a:0:{}s:3:"sup";a:0:{}s:5:"table";a:0:{}s:2:"td";a:0:{}s:2:"th";a:0:{}s:2:"tr";a:0:{}s:2:"tt";a:0:{}s:2:"ul";a:0:{}}','a:21:{s:1:"a";a:2:{s:4:"href";i:1;s:5:"title";i:1;}s:1:"b";a:0:{}s:10:"blockquote";a:0:{}s:2:"br";a:0:{}s:4:"code";a:0:{}s:3:"del";a:0:{}s:2:"em";a:0:{}s:1:"i";a:0:{}s:3:"img";a:2:{s:3:"src";i:1;s:3:"alt";i:1;}s:3:"ins";a:0:{}s:2:"li";a:0:{}s:2:"ol";a:0:{}s:1:"p";a:0:{}s:3:"pre";a:0:{}s:3:"sup";a:0:{}s:5:"table";a:0:{}s:2:"td";a:0:{}s:2:"th";a:0:{}s:2:"tr";a:0:{}s:2:"tt";a:0:{}s:2:"ul";a:0:{}}',"array","This variable controls input filtering. HTML tags and their attributes, which are not in this list, get filtered out when new RSS items are imported.",NULL),
483                "rss.output.showfeedmeta"       =>              array('false','false','boolean','Display meta-information (like a web- and rss/rdf/xml url) about each feed in the feed side-column.',NULL),
484                //"rss.input.tags.delicious"    =>              array('false','false','boolean','Look up tag suggestions on del.icio.us when editing item tags.',NULL),
485                "rss.output.frontpage.numitems" =>              array("100","100","num","Maximum number of items displayed on the main page. Set this variable to 0 to show no items on the main page.",NULL),
486                "rss.output.frontpage.mixeditems"       => array('true','true','boolean','Show read items along with unread items on the front page?',NULL),
487                "rss.output.frontpage.numreaditems"     => array(-1,-1,'num','If there are no unread items then how many items to show on the frontpage. Set this to -1 if you want it to be the same as rss.output.numitemsonmainpage',NULL),
488                "rss.output.theme"                      =>              array('default','default','string','The theme to use. Download more themes from the <a href="http://themes.gregarius.net/">Gregarius Themes Repository</a>.',NULL),
489                "rss.output.cachecontrol"       =>              array('false','false','boolean','If true, Gregarius will negotiate with the browser and check whether it should get a fresh document or not.',NULL),
490                "rss.config.plugins"            =>              array('a:2:{i:0;s:13:"urlfilter.php";i:1;s:18:"roundedcorners.php";}','a:2:{i:0;s:13:"urlfilter.php";i:1;s:18:"roundedcorners.php";}','array','Plugins are third-party scripts that offer extended functionalities. More plugins can be found at the <a href="http://plugins.gregarius.net/">Plugin Repository</a>.' , NULL),
491                "rss.input.allowupdates"        =>              array('true','true','boolean','Allow Gregarius to see if new items are updates of existing items.',NULL),
492                "rss.output.titleunreadcnt"     =>              array('false','false','boolean','Display unread count in the document title.',NULL),
493                "rss.config.tzoffset"           =>              array('0','0','num','Timezone offset, in hours, between your local time and server time. Valid range: "-12" through "12"',NULL),
494                "rss.config.feedgrouping"       =>              array('false','false','boolean',"When true, Gregarius groups unread items per feed and sorts the feeds according to the <code>rss.config.absoluteordering</code> configuration switch. When false, unread items are not grouped by feed, but are sorted by date instead.",NULL),
495                "rss.config.datedesc.unread"            =>              array('true','true','boolean',"When true, Gregarius displays newer <strong>unread</strong> items first. If false, Gregarius will display older unread items first.",NULL),
496                "rss.config.datedesc.read"              =>              array('true','true','boolean',"When true, Gregarius displays newer <strong>read</strong> items first. If false, Gregarius will display older read items first.",NULL),
497                "rss.config.autologout"         =>              array('false','false','boolean','When true, Gregarius will automatically remove the "admin cookie" when the browser window is closed, effectively logging you out.',NULL),
498                "rss.config.publictagging"      =>              array('false','false','boolean','When true, every visitor to your Gregarius site will be allowed to tag items, when false only the Administrator (you) is allowed to tag.',NULL),
499                "rss.config.rating"                     =>              array('true','true','boolean','Enable the item rating system.',NULL),
500                "rss.output.barefrontpage"                      =>              array('false','false','boolean','Suppress the output of any read item on the front page.',NULL),
501                "rss.output.title"                      => array('Gregarius','Gregarius','string','Sets the title of this feedreader.',NULL),
502                "rss.config.ajaxparallelsize"                   => array('3','3','num','Sets the number of feeds to update in parallel. Remember to set rss.config.serverpush to false.',NULL),
503                "rss.config.ajaxbatchsize"                      => array('3','3','num','Sets the number of feeds in a batch when using the ajax updater. Remember to set rss.config.serverpush to false.',NULL),
504                "rss.config.defaultdashboard"                   => array('true','true','boolean','If the first page seen when entering the admin section should be the dashboard',NULL),
505                "rss.config.deadthreshhold"     =>      array('24', '24', 'num', 'Sets the threshold for when a feed is marked as dead, in hours', NULL),
506                "rss.search.maxitems" => array(500, 500, 'num', 'Sets the maximum number of items returned on a search', NULL),
507                "rss.config.restrictrefresh"    => array("false","false","boolean","Restrict refresh to command line only (eg php -f update.php). Useful for busy sites with multiple users.",NULL),
508        );
509       
510       
511        // just send in all config entry again, ignore duplicate row errors
512        $atLeastOneIn = false;
513        foreach($defaults as $k=>$vs) {
514                list($v,$d,$t,$ds,$e) = $vs;
515            $ds=rss_real_escape_string($ds);
516            $e=rss_real_escape_string($e);
517                rss_query_wrapper('insert into '. getTable('config') 
518                        . "(key_,value_,default_,type_,desc_,export_) VALUES ("
519                        . "'$k','$v','$d','$t','$ds'," .($e?"'$e'":"null") .")",false,true);
520                if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
521
522                        $atLeastOneIn = true;
523                }
524               
525        }
526        return $atLeastOneIn;
527}
528
529///////////////////////////////////////////////////////////////////////////////
530
531function _init_item() {
532        $table = getTable('item');
533        rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true);
534        $sql_create = str_replace('__table__',$table, <<< _SQL_
535                CREATE TABLE __table__ (
536                  id bigint(16) NOT NULL auto_increment,
537                  cid bigint(11) NOT NULL default '0',
538                  md5sum varchar(32) default NULL,
539                  guid text default NULL,
540                  added datetime NOT NULL default '0000-00-00 00:00:00',
541                  title varchar(255) default NULL,
542                  url varchar(255) default NULL,
543                  enclosure varchar(255) default NULL,
544                  description text,
545                  pubdate datetime default NULL,
546                  author varchar(255) default NULL,               
547                  PRIMARY KEY  (id),
548                  KEY url (url),
549                  KEY guid(guid(10)),
550                  KEY cid (cid),
551                  KEY author (author)
552                ) TYPE=MyISAM;   
553_SQL_
554);
555
556        rss_query_wrapper($sql_create, false, true);
557        if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
558                rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR);
559                return 0;
560        } else {
561                return 1;
562        }
563}
564
565///////////////////////////////////////////////////////////////////////////////
566
567function _init_tag() {
568        $table = getTable('tag');
569        rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true);
570        $sql_create = str_replace('__table__',$table, <<< _SQL_
571                CREATE TABLE __table__ (
572                        id bigint(16) NOT NULL auto_increment,
573                        tag varchar(63) NOT NULL default '',                   
574                        PRIMARY KEY  (id),
575                        UNIQUE KEY tag (tag),
576                        KEY id (id)
577                ) TYPE=MyISAM;   
578_SQL_
579);
580
581        rss_query_wrapper($sql_create, false, true);
582        if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
583                rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR);
584                return 0;
585        } else {
586                return 1;
587        }
588}
589
590
591///////////////////////////////////////////////////////////////////////////////
592
593function _init_metatag() {
594        $table = getTable('metatag');
595        rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true);
596        $sql_create = str_replace('__table__',$table, <<< _SQL_
597                CREATE TABLE __table__ (
598                        fid bigint(16) NOT NULL default '0',
599                        tid bigint(16) NOT NULL default '0',
600                        fkuid bigint(16) NOT NULL default '1',
601                        ttype enum('item','folder','channel') NOT NULL default 'item',
602                        KEY fid (fid),
603                        KEY tid (tid),
604                        KEY fkuid (fkuid),
605                        KEY ttype (ttype)
606                ) TYPE=MyISAM;
607_SQL_
608);
609
610        rss_query_wrapper($sql_create, false, true);
611        if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
612                rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR);
613                return 0;
614        } else {
615                return 1;
616        }
617}
618
619///////////////////////////////////////////////////////////////////////////////
620
621function _init_rating() {
622        $table = getTable('rating');
623        rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true);
624        $sql_create = str_replace('__table__',$table, <<< _SQL_
625                CREATE TABLE __table__ (
626                        iid bigint(16)  NOT NULL,
627                        rating tinyint(4) default '0'
628                ) TYPE=MyISAM;
629_SQL_
630);
631
632        rss_query_wrapper($sql_create, false, true);
633        if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
634                rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR);
635                return 0;
636        } else {
637                return 1;
638        }
639}
640
641
642///////////////////////////////////////////////////////////////////////////////
643
644function _init_cache() {
645        $table = getTable('cache');
646        rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true);
647        $sql_create = str_replace('__table__',$table, <<< _SQL_
648                CREATE TABLE __table__ (
649                cachekey VARCHAR( 128 ) NOT NULL ,
650                timestamp DATETIME NOT NULL ,
651                cachetype ENUM( 'ts', 'icon', 'feed' ) NOT NULL ,
652                data BLOB,
653                PRIMARY KEY ( cachekey )
654                ) TYPE=MYISAM;
655_SQL_
656);
657
658        rss_query_wrapper($sql_create, false, true);
659       
660
661       
662        if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
663                rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR);
664                return 0;
665        } else {
666
667                rss_query_wrapper ("INSERT INTO $table (cachekey,timestamp,cachetype,data) VALUES ('data_ts',now(),'ts',null)", false, true);   
668                if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
669                        rss_error('The '  . $table .  ' table was created successfully, but I couldn\'t insert the default values. Please do so manually!', RSS_ERROR_ERROR);
670                        return 0;
671                }
672       
673                return 1;
674        }
675}
676
677///////////////////////////////////////////////////////////////////////////////
678
679function _init_users() {
680        $table = getTable('users');
681        rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true);
682        $sql_create = str_replace('__table__',$table, <<< _SQL_
683                CREATE TABLE __table__ (
684                  uid bigint(16) NOT NULL auto_increment,
685                  uname varchar(255) NOT NULL,
686                  password varchar(255) NOT NULL,
687                  ulevel bigint(11) NOT NULL default '1',
688                  realname varchar(255) default NULL,
689                  lastip varchar(255) default NULL,
690                  userips TEXT default '',
691                  lastlogin datetime NULL default '0000-00-00 00:00:00',
692                  PRIMARY KEY  (uid),
693                  KEY (uname)
694                ) TYPE=MyISAM; 
695_SQL_
696);
697
698        rss_query_wrapper($sql_create, false, true);
699       
700
701       
702        if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
703                rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR);
704                return 0;
705        } else {
706
707                rss_query_wrapper ("INSERT INTO $table (uname,password,ulevel,realname) VALUES ('admin','',99,'Administrator')", false, true); 
708                if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
709                        rss_error('The '  . $table .  ' table was created successfully, but I couldn\'t insert the default values. Please do so manually!', RSS_ERROR_ERROR);
710                        return 0;
711                }
712       
713                return 1;
714        }
715}
716
717function _init_channels2user() {
718        $table = getTable('channels2user');
719        rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true);
720        $sql_create = str_replace('__table__',$table, <<< _SQL_
721                CREATE TABLE __table__ (
722                  id bigint(16) not null auto_increment,
723                  fkcid bigint(16) NOT NULL,
724                  fkuid bigint(16) NOT NULL,
725                  flgprivate tinyint(1) NOT NULL default '0',
726                  flgdeleted tinyint(1) not null default '0',
727                  primary key (id),
728                  KEY flgprivate (flgprivate),
729                  KEY flgdeleted (flgdeleted),
730                  KEY fkuid (fkuid),
731                  KEY iids (fkcid)
732                ) ENGINE=MyISAM;
733_SQL_
734);
735
736
737        rss_query_wrapper($sql_create, false, true);
738
739        if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
740                rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR);
741                return 0;
742        } else {
743                $fillSql = "insert into $table "
744                ." (fkcid,fkuid,icon,position,parent,flgprivate,flgdeleted) "
745                ."select id, " . rss_user_id() . ", icon, position, parent, "
746                ." mode & ".RSS_MODE_PRIVATE_STATE." = ".RSS_MODE_PRIVATE_STATE.", "
747                ." mode & ".RSS_MODE_DELETED_STATE." = ".RSS_MODE_DELETED_STATE." "
748                ." from " .getTable('channels')
749                ." where url != ''";
750                //die($fillSql);
751                rss_query_wrapper($fillSql, false, true);
752               
753                rss_query(
754                        'update ' .getTable('metatag') .' m '
755                        .'set m.fkuid=' .rss_user_id());
756                /*
757                $rs = rss_query( "select id, fkcid from " .getTable('channels2user'));
758                $cids=array();
759                while(list($c2uid,$cid) = rss_fetch_row($rs)) {
760                        $cids[$cid]=$c2uid;
761                }
762                */
763                return rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR);
764        }
765}
766
767function _init_item2user() {
768        $table = getTable('item2user');
769        rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true);
770        $sql_create = str_replace('__table__',$table, <<< _SQL_
771                CREATE TABLE __table__ (
772                  fkiid bigint(16) NOT NULL,
773                  fkuid bigint(16) NOT NULL,
774                  fkcid bigint(11) NOT NULL,
775                  flgunread tinyint(1) NOT NULL default '1',
776                  flgsticky tinyint(1) NOT NULL default '0',
777                  flgprivate tinyint(1) NOT NULL default '0',
778                  flgdeleted tinyint(1) NOT NULL default '0',
779                  flgflagged tinyint(1) NOT NULL default '0',
780                  KEY flgunread (flgunread),
781                  KEY flgsticky (flgsticky),
782                  KEY flgprivate (flgprivate),
783                  KEY flgdeleted (flgdeleted),
784                  KEY flgflagged (flgflagged),
785                  KEY fkuid (fkuid),
786                  KEY iids (fkiid)
787                ) ENGINE=MyISAM;
788_SQL_
789);
790
791        rss_query_wrapper($sql_create, false, true);
792
793        if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
794                rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR);
795                return 0;
796        } else {
797                $fillSql = "insert into $table (fkiid,fkuid,fkcid,flgunread,flgsticky,flgprivate,flgdeleted,flgflagged) "
798                ."select id, " . rss_user_id() . ", cid, "
799                ." unread & ".RSS_MODE_UNREAD_STATE." = ".RSS_MODE_UNREAD_STATE.", "
800                ." unread & ".RSS_MODE_STICKY_STATE." = ".RSS_MODE_STICKY_STATE.", "
801                ." unread & ".RSS_MODE_PRIVATE_STATE." = ".RSS_MODE_PRIVATE_STATE.", "
802                ." unread & ".RSS_MODE_DELETED_STATE." = ".RSS_MODE_DELETED_STATE.", "
803                ." unread & ".RSS_MODE_FLAG_STATE." = ".RSS_MODE_FLAG_STATE." from " .getTable('item');
804                rss_query_wrapper($fillSql, false, true);
805
806                return rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR);
807        }
808}
809
810
811///////////////////////////////////////////////////////////////////////////////
812
813
814function _init_properties() {
815        $table = getTable('properties');
816        rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true);
817        $sql_create = str_replace('__table__',$table, <<< _SQL_
818                CREATE TABLE __table__ (
819                  fk_ref_object_id text NOT NULL,
820                  proptype enum('item','feed','folder','category','plugin','tag','theme','misc') NOT NULL default 'item',
821                  property varchar(128) NOT NULL default '',
822                  value text NOT NULL
823                ) TYPE=MyISAM;
824               
825_SQL_
826);
827
828        rss_query_wrapper($sql_create, false, true);
829        if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) {
830                rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR);
831                return 0;
832        } else {
833                $idSql = "alter table $table add UNIQUE KEY uniq (fk_ref_object_id(180),property,proptype)";
834                rss_query_wrapper($idSql, false, true);
835                return rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR);
836        }
837}
838
839
840///////////////////////////////////////////////////////////////////////////////
841
842if (isset($argv) && in_array('--dump',$argv)) {
843        foreach ($argv as $idx => $arg) {
844                if (substr($arg,0,9) == '--prefix=') {
845                        define ('DB_TABLE_PREFIX',substr($arg,9));
846                }
847        }
848        define ('DUMP_SCHEMA', true);
849        define ('PROFILING', false);
850        @require_once('init.php');
851       
852        $out = "################
853# Gregarius " . _VERSION_ . "
854# database structure
855#################
856
857";
858        foreach (array("channels","config","folders","item","metatag","tag","rating", "users", "dashboard","item2user","channels2user") as $tbl) {
859                call_user_func("_init_$tbl"); 
860        }
861        // shamelessly copied from install.php
862                $fp = @fopen(DBSTRUCT, 'w');
863                if(!$fp) {
864                        // unable to open file for writing
865                        echo($out);
866                        exit();
867                } else {
868                        // write the file
869                        fwrite($fp, $out);
870                        fclose($fp);
871                        echo "The database structure has been written to the file 'dbstruct.sql'.\n";
872                        exit();
873                }
874}
875
876?>
Note: See TracBrowser for help on using the browser.