function setupDB()
 {
     global $serendipity;
     if (serendipity_db_bool($this->get_config('db_built', false))) {
         return true;
     }
     #FIXME:  Add hooks for XML / exporting to convert images/text to ascii art/text or text-only.
     #  That doesn't belong here.
     $sql = "CREATE TABLE {$serendipity['dbPrefix']}mymood (\n                      mood_id {AUTOINCREMENT} {PRIMARY},\n                      mood_name     varchar(255) NOT NULL default '',\n                      mood_img      varchar(255) NOT NULL default '',\n                      mood_ascii    varchar(255) NOT NULL default ''\n                    )";
     serendipity_db_schema_import($sql);
     # Setting up some basic moods...
     $moods = array();
     $default_moods = explode('|`|', PLUGIN_MYMOOD_LISTOFMOODS);
     foreach ($default_moods as $mood_s) {
         $info_array = explode('|~|', $mood_s);
         $moods[] = array('mood_name' => $info_array[0], 'mood_img' => $info_array[1], 'mood_ascii' => $info_array[2]);
     }
     #gar!  hafta check if there's already one defined...stupid 5000 'Happy's in my db...
     #fixme:  this may need some sort of case insensitive stuff...
     # also will want to add that to the adding part..
     foreach ($moods as $mood_array) {
         $check_q = "SELECT mood_id FROM {$serendipity['dbPrefix']}mymood WHERE mood_name='{$mood_array['mood_name']}'";
         $t = serendipity_db_query($check_q);
         if (!empty($t[0])) {
             continue;
         }
         $insert_q = "INSERT INTO {$serendipity['dbPrefix']}mymood\n                       (mood_name, mood_img, mood_ascii)\n                       VALUES (\n                       '{$mood_array['mood_name']}', '{$mood_array['mood_img']}','{$mood_array['mood_ascii']}')";
         serendipity_db_query($insert_q);
     }
     $this->set_config('db_built', 'true');
 }
 function check_lj_entries()
 {
     global $serendipity;
     if (!is_array(serendipity_db_query("SELECT id FROM {$serendipity['dbPrefix']}lj_entries LIMIT 1", true, 'both', false, false, false, true))) {
         serendipity_db_schema_import("CREATE TABLE {$serendipity['dbPrefix']}lj_entries (\n              entry_id int default null,\n              itemid int default null,\n              current_mood varchar(255) default null,\n              current_music varchar(255) default null,\n              picture_keyword varchar(255) default null,\n              security varchar(255) default null,\n              opt_nocomments varchar(255) default null\n            );");
     }
 }
 function setupDB()
 {
     global $serendipity;
     if (serendipity_db_bool($this->get_config('db_built4', false))) {
         return true;
     }
     if (serendipity_db_bool($this->get_config('db_built3', false))) {
         $sql = "UPDATE {$serendipity['dbPrefix']}mycalendar SET eventdate2 = eventdate WHERE (eventdate2 = 0) OR eventdate2 IS NULL;";
         serendipity_db_schema_import($sql);
         $this->set_config('db_built4', 'true');
         return true;
     }
     if (serendipity_db_bool($this->get_config('db_built2', false))) {
         $sql = "ALTER TABLE {$serendipity['dbPrefix']}mycalendar ADD eventdate2 int(10) {UNSIGNED} default null;";
         serendipity_db_schema_import($sql);
         $this->set_config('db_built3', 'true');
         return true;
     }
     if (serendipity_db_bool($this->get_config('db_built', false))) {
         $sql = "ALTER TABLE {$serendipity['dbPrefix']}mycalendar ADD eventurltitle varchar(255) default null;";
         serendipity_db_schema_import($sql);
         $this->set_config('db_built2', 'true');
         return true;
     }
     $sql = "CREATE TABLE {$serendipity['dbPrefix']}mycalendar (\n                      eventid {AUTOINCREMENT} {PRIMARY},\n                      eventname     varchar(255) NOT NULL default '',\n                      eventurl      varchar(255) NOT NULL default '',\n                      eventurltitle varchar(255) NOT NULL default '',\n                      eventdate     int(10) {UNSIGNED} default null,\n                      eventdate2    int(10) {UNSIGNED} default null,\n                      eventcategory varchar(255) NOT NULL default '',\n                      eventtype     varchar(255) NOT NULL default ''\n                    );";
     serendipity_db_schema_import($sql);
     $this->set_config('db_built4', 'true');
 }
 function install()
 {
     global $serendipity;
     if (!$this->tableCreated('facebook')) {
         $q = "CREATE TABLE {$serendipity['dbPrefix']}facebook (\n                    entryid int(10) not null,\n                    base_url varchar(255),\n                    resolved_url varchar(255)\n                  )";
         $result = serendipity_db_schema_import($q);
         serendipity_db_schema_import("CREATE INDEX fbindex ON {$serendipity['dbPrefix']}facebook (base_url)");
     }
 }
 function setupDB()
 {
     global $serendipity;
     $built = $this->get_config('db_built', null);
     if (empty($built)) {
         serendipity_db_schema_import("CREATE TABLE {$serendipity['dbPrefix']}dejure (\n                    ckey varchar(32),\n                    cache text,\n                    last_update int(10) {UNSIGNED}\n                    )");
         serendipity_db_schema_import('CREATE UNIQUE INDEX dejure_cacheidx ON {PREFIX}dejure (ckey)');
     }
 }
 function setupDB()
 {
     global $serendipity;
     $built = $this->get_config('db_built', null);
     if (empty($built)) {
         $q = "@CREATE {FULLTEXT_MYSQL} INDEX commentbody_idx on {$serendipity['dbPrefix']}comments (title, body);";
         serendipity_db_schema_import($q);
         $this->set_config('db_built', 1);
     }
 }
 function setupDB()
 {
     global $serendipity;
     $built = $this->get_config('db_built', null);
     $fresh = false;
     if (empty($built) && !defined('VERSIONING_UPGRADE_DONE')) {
         serendipity_db_schema_import("CREATE TABLE {$serendipity['dbPrefix']}versioning (\r\n                    id {AUTOINCREMENT} {PRIMARY},\r\n                    entry_id int(11) default '0',\r\n                    version int(4) default '1',\r\n                    body text,\r\n                    extended text,\r\n                    version_date int(11) default '0',\r\n                    version_author int(4) default '0'\r\n            )");
         $this->set_config('db_built', '1');
         @define('VERSIONING_UPGRADE_DONE', true);
     }
 }
 function setupDB()
 {
     global $serendipity;
     if (serendipity_db_bool($this->get_config('db_built_1', false))) {
         return true;
     }
     $sql = "CREATE TABLE {$serendipity['dbPrefix']}adminnotes (\n                      noteid {AUTOINCREMENT} {PRIMARY},\n                      authorid int(10) {UNSIGNED} default null,\n                      notetime int(10) {UNSIGNED} default null,\n                      subject varchar(255),\n                      body text,\n                      notetype     varchar(255) NOT NULL default ''\n                    );";
     serendipity_db_schema_import($sql);
     $sql = "CREATE TABLE {$serendipity['dbPrefix']}adminnotes_to_groups (\n                      noteid int(10) {UNSIGNED} default null,\n                      groupid int(10) {UNSIGNED} default null\n                    );";
     serendipity_db_schema_import($sql);
     $this->set_config('db_built_1', 'true');
 }
 function checkScheme()
 {
     global $serendipity;
     $version = $this->get_config('version', 'none');
     if ($version == 'none') {
         $q = "CREATE TABLE {$serendipity['dbPrefix']}markread (\n                        entryid int(11) default null,\n                        visitor varchar(64) default null,\n                        read_date int(10) {UNSIGNED} NULL\n                    )";
         $sql = serendipity_db_schema_import($q);
         $q = "CREATE INDEX readfetch ON {$serendipity['dbPrefix']}markread (entryid, visitor);";
         $sql = serendipity_db_schema_import($q);
         $this->set_config('version', '1.0');
     }
     return true;
 }
Пример #10
0
 static function install(&$obj)
 {
     global $serendipity;
     if (!OEmbedDatabase::table_created(PLUGIN_OEMBED_DATABASEVNAME)) {
         $md5test = md5("test");
         $md5len = strlen($md5test);
         $q = "create table {$serendipity['dbPrefix']}" . PLUGIN_OEMBED_DATABASEVNAME . " (" . "urlmd5 char({$md5len}) not null, " . "url varchar(3000) not null, " . "oetype varchar(20) not null, " . "oeobj text not null, " . "primary key (urlmd5)" . ")";
         $result = serendipity_db_schema_import($q);
         if ($result !== true) {
             return;
         }
     }
 }
 function setupDB()
 {
     global $serendipity;
     $built = $this->get_config('db_built', null);
     if (empty($built) && !defined('PLUGIN_POLL_UPGRADE_DONE')) {
         serendipity_db_schema_import("CREATE TABLE {$serendipity['dbPrefix']}polls (\n              id {AUTOINCREMENT} {PRIMARY},\n              title varchar(255) not null default '',\n              content text,\n              active int(1) default '1',\n              votes int(4) default '0',\n              timestamp int(10) {UNSIGNED} default null);");
         serendipity_db_schema_import("CREATE TABLE {$serendipity['dbPrefix']}polls_options (\n              id {AUTOINCREMENT} {PRIMARY},\n              pollid int(10) {UNSIGNED},\n              title varchar(255) not null default '',\n              votes int(4) default '0',\n              timestamp int(10) {UNSIGNED} default null);");
         serendipity_db_schema_import("CREATE INDEX pollidx ON {PREFIX}polls_options (pollid);");
         $this->set_config('db_built', '1');
         @define('PLUGIN_POLL_UPGRADE_DONE', true);
         // No further static pages may be called!
     }
 }
 function setupDB()
 {
     global $serendipity;
     if (serendipity_db_bool($this->get_config('db_built_1', false))) {
         return true;
     }
     if (preg_match('@mysql@i', $serendipity['dbType'])) {
         $sql = "CREATE TABLE {$serendipity['dbPrefix']}linktrimmer (\n                          id {AUTOINCREMENT} {PRIMARY},\n                          hash varchar(32) collate latin1_general_cs,\n                          url text\n                        );";
     } else {
         $sql = "CREATE TABLE {$serendipity['dbPrefix']}linktrimmer (\n                          id {AUTOINCREMENT} {PRIMARY},\n                          hash varchar(32),\n                          url text\n                        );";
     }
     serendipity_db_schema_import($sql);
     $sql = "CREATE INDEX linkidx ON {$serendipity['dbPrefix']}linktrimmer (hash)";
     serendipity_db_schema_import($sql);
     $this->set_config('db_built_1', 'true');
 }
 function setupDB()
 {
     global $serendipity;
     $q = "CREATE TABLE {$serendipity['dbPrefix']}dma_sqlbackup (\n\t\t\t\t\tauto_backup \tint(2)\t\tNOT NULL \tdefault '0',\n\t\t\t\t\ttime_backup \tint(10)\t\tNOT NULL \tdefault '0',\n\t\t\t\t\tlast_backup \tint(10) \tNOT NULL \tdefault '0',\n\t\t\t\t\tdata_backup \ttext \t\tNOT NULL,\n\t\t\t\t\tauto_backdel \tint(2) \t\tNOT NULL \tdefault '0',\n\t\t\t\t\ttime_backdel \tint(10) \tNOT NULL \tdefault '0',\n\t\t\t\t\tlast_backdel \tint(10) \tNOT NULL \tdefault '0'\n\t\t\t)";
     $sql = serendipity_db_schema_import($q);
     $q = "CREATE TABLE {$serendipity['dbPrefix']}dma_htmlbackup (\n\t\t\t\t\tauto_backup \tint(2)\t\tNOT NULL \tdefault '0',\n\t\t\t\t\ttime_backup \tint(10)\t\tNOT NULL \tdefault '0',\n\t\t\t\t\tlast_backup \tint(10) \tNOT NULL \tdefault '0',\n\t\t\t\t\tdata_backup \ttext \t\tNOT NULL,\n\t\t\t\t\tauto_backdel \tint(2) \t\tNOT NULL \tdefault '0',\n\t\t\t\t\ttime_backdel \tint(10) \tNOT NULL \tdefault '0',\n\t\t\t\t\tlast_backdel \tint(10) \tNOT NULL \tdefault '0'\n\t\t\t)";
     $sql = serendipity_db_schema_import($q);
     $q = "TRUNCATE TABLE {$serendipity['dbPrefix']}dma_sqlbackup";
     $sql = serendipity_db_schema_import($q);
     $q = "TRUNCATE TABLE {$serendipity['dbPrefix']}dma_htmlbackup";
     $sql = serendipity_db_schema_import($q);
     $q = "INSERT INTO {$serendipity['dbPrefix']}dma_sqlbackup (\n\t\t\t\t\tauto_backup,\n\t\t\t\t\ttime_backup,\n\t\t\t\t\tlast_backup,\n\t\t\t\t\tdata_backup,\n\t\t\t\t\tauto_backdel,\n\t\t\t\t\ttime_backdel,\n\t\t\t\t\tlast_backdel\n\t\t) VALUES (\n\t\t\t\t\t'0',\n\t\t\t\t\t'0',\n\t\t\t\t\t'0',\n\t\t\t\t\t'',\n\t\t\t\t\t'0',\n\t\t\t\t\t'0',\n\t\t\t\t\t'0'\n\t\t)";
     $sql = serendipity_db_schema_import($q);
     $q = "INSERT INTO {$serendipity['dbPrefix']}dma_htmlbackup (\n\t\t\t\t\tauto_backup,\n\t\t\t\t\ttime_backup,\n\t\t\t\t\tlast_backup,\n\t\t\t\t\tdata_backup,\n\t\t\t\t\tauto_backdel,\n\t\t\t\t\ttime_backdel,\n\t\t\t\t\tlast_backdel\n\t\t) VALUES (\n\t\t\t\t\t'0',\n\t\t\t\t\t'0',\n\t\t\t\t\t'0',\n\t\t\t\t\t'',\n\t\t\t\t\t'0',\n\t\t\t\t\t'0',\n\t\t\t\t\t'0'\n\t\t)";
     $sql = serendipity_db_schema_import($q);
 }
 function checkScheme()
 {
     global $serendipity;
     $version = $this->get_config('version', '0.9');
     if ($version != PLUGIN_EVENT_PHOTOBLOG_VERSION) {
         if ((double) $version < 1.0) {
             $q = "CREATE TABLE {$serendipity['dbPrefix']}photoblog (\n                            entryid int(11) default null,\n                            photoid int(11) default null\n                        )";
             $sql = serendipity_db_schema_import($q);
             $q = "CREATE INDEX kentryid ON {$serendipity['dbPrefix']}photoblog (entryid);";
             $sql = serendipity_db_schema_import($q);
         }
         if ((double) $version < 1.2) {
             $q = "ALTER TABLE {$serendipity['dbPrefix']}photoblog ADD use_thumbnail {BOOLEAN};";
             $sql = serendipity_db_schema_import($q);
             $q = "UPDATE {$serendipity['dbPrefix']}photoblog SET use_thumbnail = '';";
             serendipity_db_query($q);
         }
         $this->set_config('version', PLUGIN_EVENT_PHOTOBLOG_VERSION);
     }
 }
Пример #15
0
 static function install(&$obj)
 {
     global $serendipity;
     $dbversion = $obj->get_config(PLUGIN_EVENT_COMMENTSPICE_CNAME_DBCONFIG);
     if (empty($dbversion)) {
         $dbversion = 0;
     }
     if (!DbSpice::table_created('commentspice')) {
         // twitternames cant be longer than 15 referring to API docs. 20 for safety. nvarchar because of unicode names
         $q = "create table {$serendipity['dbPrefix']}commentspice (" . "commentid int(10) not null, " . "twittername nvarchar(20), " . "primary key (commentid)" . ")";
         $result = serendipity_db_schema_import($q);
         if ($result !== true) {
             return;
         }
         $obj->set_config(PLUGIN_EVENT_COMMENTSPICE_CNAME_DBCONFIG, 1);
     }
     // Version 2 updates
     if ($obj->get_config(PLUGIN_EVENT_COMMENTSPICE_CNAME_DBCONFIG < 2)) {
         $q = "alter table {$serendipity['dbPrefix']}commentspice" . " add column promo_name nvarchar(200)," . " add column promo_url nvarchar(250);";
         serendipity_db_query($q);
         $obj->set_config(PLUGIN_EVENT_COMMENTSPICE_CNAME_DBCONFIG, 2);
     }
     // Version 3 updates
     if ($obj->get_config(PLUGIN_EVENT_COMMENTSPICE_CNAME_DBCONFIG < 3)) {
         $q = "CREATE INDEX IDX_COMMENTS_EMAIL" . " on {$serendipity['dbPrefix']}comments (email);";
         serendipity_db_query($q);
         // if it already exists, it won't be created
         $obj->set_config(PLUGIN_EVENT_COMMENTSPICE_CNAME_DBCONFIG, 3);
     }
     // Version 4 updates
     if ($obj->get_config(PLUGIN_EVENT_COMMENTSPICE_CNAME_DBCONFIG < 4)) {
         $q = "alter table {$serendipity['dbPrefix']}commentspice" . " add column boo nvarchar(250);";
         serendipity_db_query($q);
         $obj->set_config(PLUGIN_EVENT_COMMENTSPICE_CNAME_DBCONFIG, 4);
     }
 }
 function checkTable()
 {
     global $serendipity;
     $q = "CREATE TABLE IF NOT EXISTS {$serendipity['dbPrefix']}tweets (\n            id bigint(11) {PRIMARY},\n            tweetdate int(11),\n            tweet longtext,\n            username varchar(255),\n            reply_to_status int(11),\n            reply_to_user int(11),\n            source varchar(255)\n            \n        );";
     serendipity_db_schema_import($q);
     $db_version = $this->get_config("db_version");
     // Convert tweet id to bigint!
     if (empty($db_version)) {
         $q = "ALTER TABLE {$serendipity['dbPrefix']}tweets CHANGE id id bigint(11)";
         serendipity_db_schema_import($q);
     }
     $this->set_config("db_version", 1);
 }
 /**
  *
  * Manage the database tables for staticpage
  *
  * @access private
  * @return void
  *
  */
 function setupDB()
 {
     global $serendipity;
     $built = $this->get_config('db_built', null);
     $fresh = false;
     if (empty($built) && !defined('STATICPAGE_UPGRADE_DONE')) {
         serendipity_db_schema_import("CREATE TABLE {$serendipity['dbPrefix']}staticpages (\n                    id {AUTOINCREMENT} {PRIMARY},\n                    parent_id int(11) default '0',\n                    articleformattitle varchar(255) not null default '',\n                    articleformat int(1) default '1',\n                    markup int(1) default '1',\n                    pagetitle varchar(255) not null default '',\n                    permalink varchar(255) not null default '',\n                    is_startpage int(1) default '0',\n                    is_404_page int(1) default '0',\n                    show_childpages int(1) not null default '0',\n                    content text,\n                    pre_content text,\n                    headline varchar(255) not null default '',\n                    filename varchar(255) not null default '',\n                    pass varchar(255) not null default '',\n                    timestamp int(10) {UNSIGNED} default null,\n                    last_modified int(10) {UNSIGNED} default null,\n                    authorid int(11) default '0',\n                    pageorder int(4) default '0',\n                    articletype int(4) default '0',\n                    related_category_id int(4) default 0,\n                    shownavi int(4) default '1',\n                    showonnavi int(4) default '1',\n                    show_breadcrumb int(4) default '1',\n                    publishstatus int(4) default '1',\n                    language varchar(10) default '') {UTF_8}");
         $old_stuff = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}config WHERE name LIKE 'serendipity_event_staticpage:%'");
         $import = array();
         if (is_array($old_stuff)) {
             foreach ($old_stuff as $item) {
                 $names = explode('/', $item['name']);
                 if (!isset($import[$names[0]])) {
                     $import[$names[0]] = array('authorid' => $item['authorid']);
                 }
                 $import[$names[0]][$names[1]] = serendipity_get_bool($item['value']);
             }
         }
         foreach ($import as $page) {
             if (is_array($page)) {
                 serendipity_db_insert('staticpages', $page);
                 @unlink($this->cachefile);
             }
         }
         serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}config  WHERE name LIKE 'serendipity_event_staticpage:%'");
         serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}plugins WHERE name LIKE 'serendipity_event_staticpage:%' AND name NOT LIKE '" . serendipity_db_escape_string($this->instance) . "'");
         $this->set_config('db_built', '7');
         $fresh = true;
         @define('STATICPAGE_UPGRADE_DONE', true);
         // No further static pages may be called!
     }
     switch ($built) {
         case 1:
             // password not included
             $q = "ALTER TABLE {$serendipity['dbPrefix']}staticpages ADD COLUMN pass varchar(255) not null default ''";
             serendipity_db_schema_import($q);
         case 2:
             // parent-id not included
             $q = "ALTER TABLE {$serendipity['dbPrefix']}staticpages ADD COLUMN parent_id int(11) default '0'";
             serendipity_db_schema_import($q);
         case 3:
             $q = "ALTER TABLE {$serendipity['dbPrefix']}staticpages ADD COLUMN show_childpages int(1) not null default '0'";
             serendipity_db_schema_import($q);
             // list of child-pages on parent-page
             $q = "ALTER TABLE {$serendipity['dbPrefix']}staticpages ADD COLUMN pre_content text";
             serendipity_db_schema_import($q);
             // content
         // content
         case 4:
             $q = "ALTER TABLE {$serendipity['dbPrefix']}staticpages ADD COLUMN is_startpage int(1) default '0'";
             serendipity_db_schema_import($q);
         case 5:
             // enum to re-order staticpages
             $q = "ALTER TABLE {$serendipity['dbPrefix']}staticpages ADD COLUMN pageorder int(4) default '0'";
             serendipity_db_schema_import($q);
         case 6:
             $q = "ALTER TABLE {$serendipity['dbPrefix']}staticpages ADD COLUMN articletype int(4) default '0'";
             serendipity_db_schema_import($q);
         case 7:
             $q = "CREATE TABLE {$serendipity['dbPrefix']}staticpages_types (\n                        id {AUTOINCREMENT} {PRIMARY},\n                        description varchar(100) not null default '',\n                        template varchar(255) not null default '',\n                        image varchar(255) not null default '') {UTF_8}";
             serendipity_db_schema_import($q);
             $existing = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}staticpages_types LIMIT 1");
             if (!is_array($existing) || !isset($existing[0]['template'])) {
                 $this->pagetype = array('description' => 'Article', 'template' => 'plugin_staticpage.tpl');
                 serendipity_db_insert('staticpages_types', $this->pagetype);
                 $this->pagetype = array('description' => 'Overview', 'template' => 'plugin_staticpage_aboutpage.tpl');
                 serendipity_db_insert('staticpages_types', $this->pagetype);
                 $set = array('articletype' => 1, 'pageorder' => 0);
                 serendipity_db_update('staticpages', array(), $set);
                 @unlink($this->cachefile);
             }
         case 8:
         case 9:
         case 10:
             if (!$fresh) {
                 $q = "ALTER TABLE {$serendipity['dbPrefix']}staticpages ADD COLUMN shownavi int(4) default '1';";
                 serendipity_db_schema_import($q);
                 $q = "ALTER TABLE {$serendipity['dbPrefix']}staticpages ADD COLUMN showonnavi int(4) default '1'";
                 serendipity_db_schema_import($q);
                 $q = "ALTER TABLE {$serendipity['dbPrefix']}staticpages ADD COLUMN publishstatus int(4) default '1';";
                 serendipity_db_schema_import($q);
                 $q = 'DROP TABLE ' . $serendipity['dbPrefix'] . 'staticpages_plugins';
                 serendipity_db_schema_import($q);
                 $q = 'ALTER TABLE ' . $serendipity['dbPrefix'] . 'staticpages ADD COLUMN language varchar(10) default \'\'';
                 serendipity_db_schema_import($q);
             }
         case 11:
             serendipity_db_update('staticpages_types', array('description' => 'Aboutpage'), array('description' => 'Overview'));
         case 12:
             $q = "CREATE {FULLTEXT_MYSQL} INDEX staticentry_idx on {$serendipity['dbPrefix']}staticpages (headline, content);";
             serendipity_db_schema_import($q);
         case 13:
         case 14:
             if (!$fresh) {
                 $q = "ALTER TABLE {$serendipity['dbPrefix']}staticpages ADD COLUMN last_modified int(10)";
                 serendipity_db_schema_import($q);
                 serendipity_db_query("UPDATE {$serendipity['dbPrefix']}staticpages SET last_modified = timestamp");
             }
         case 15:
             if (!$fresh) {
                 $sql = 'ALTER TABLE ' . $serendipity['dbPrefix'] . 'staticpages ADD COLUMN related_category_id int(4) default 0';
                 serendipity_db_schema_import($sql);
             }
         case 16:
             $this->pagetype = array('description' => 'Staticpage with related category', 'template' => 'plugin_staticpage_related_category.tpl');
             serendipity_db_insert('staticpages_types', $this->pagetype);
             $sql = 'CREATE TABLE ' . $serendipity['dbPrefix'] . 'staticpage_categorypage (
                         categoryid int(4) default 0,
                         staticpage_categorypage int(4) default 0
                     ) {UTF_8}';
             serendipity_db_schema_import($sql);
         case 17:
             $sql = 'CREATE TABLE ' . $serendipity['dbPrefix'] . 'staticpage_custom (
                         staticpage int(11),
                         name varchar(128),
                         value text
                     ) {UTF_8}';
             serendipity_db_schema_import($sql);
         case 18:
             $sql = 'ALTER TABLE ' . $serendipity['dbPrefix'] . 'staticpages ADD COLUMN is_404_page int(1) default 0';
             if ($serendipity['dbType'] == 'mysql' || $serendipity['dbType'] == 'mysqli') {
                 $sql .= ' AFTER is_startpage';
             }
             serendipity_db_schema_import($sql);
         case 19:
             if (!$fresh) {
                 $q = "ALTER TABLE {$serendipity['dbPrefix']}staticpages ADD COLUMN show_breadcrumb int(4) default '1'";
                 serendipity_db_schema_import($q);
             }
         case 20:
             if (!$fresh) {
                 $q = "ALTER TABLE {$serendipity['dbPrefix']}staticpages ADD COLUMN title_element varchar(255) not null default ''";
                 serendipity_db_schema_import($q);
                 $q = "ALTER TABLE {$serendipity['dbPrefix']}staticpages ADD COLUMN meta_description varchar(255) not null default ''";
                 serendipity_db_schema_import($q);
                 $q = "ALTER TABLE {$serendipity['dbPrefix']}staticpages ADD COLUMN meta_keywords varchar(255) not null default ''";
                 serendipity_db_schema_import($q);
             }
             $this->set_config('db_built', 21);
             break;
     }
 }
Пример #18
0
 static function updateOpenID($openid_url, $authorID)
 {
     global $serendipity;
     if (!is_array(serendipity_db_query("SELECT username FROM {$serendipity['dbPrefix']}openid_authors LIMIT 1", true, 'both', false, false, false, true))) {
         serendipity_db_schema_import("CREATE TABLE {$serendipity['dbPrefix']}openid_authors (\r\n              openid_url varchar(255) default null,\r\n              hash varchar(32) default null,\r\n              authorid int(11) default '0'\r\n            );");
     }
     $hash = md5($openid_url);
     if (serendipity_common_openid::getOpenID($authorID, true)) {
         $retVal = serendipity_db_update('openid_authors', array('authorid' => $authorID), array('openid_url' => $openid_url, 'hash' => $hash));
     } else {
         $retVal = serendipity_db_insert('openid_authors', array('openid_url' => $openid_url, 'hash' => $hash, 'authorid' => $authorID));
     }
     return $retVal === true ? true : false;
 }
 /**
  * Updates database to version-appropriate schema
  * @param The current version number of the database (could be empty)
  * @return true
  */
 function checkScheme($ver)
 {
     global $serendipity;
     if ($ver == 3) {
         $q = "ALTER TABLE {$serendipity['dbPrefix']}categorytemplates ADD COLUMN hide_rss varchar(4) default false";
         $sql = serendipity_db_schema_import($q);
         $this->set_config('dbversion', CATEGORYTEMPLATE_DB_VERSION);
     } elseif ($ver == 2) {
         $q = "ALTER TABLE {$serendipity['dbPrefix']}categorytemplates ADD COLUMN hide_rss varchar(4) default false";
         $sql = serendipity_db_schema_import($q);
         $q = "ALTER TABLE {$serendipity['dbPrefix']}categorytemplates ADD COLUMN sort_order varchar(255)";
         $sql = serendipity_db_schema_import($q);
         $this->set_config('dbversion', CATEGORYTEMPLATE_DB_VERSION);
     } elseif ($ver == 1) {
         $q = "ALTER TABLE {$serendipity['dbPrefix']}categorytemplates ADD COLUMN hide_rss tinyint(1) default false";
         $sql = serendipity_db_schema_import($q);
         $q = "ALTER TABLE {$serendipity['dbPrefix']}categorytemplates ADD COLUMN sort_order varchar(255)";
         $sql = serendipity_db_schema_import($q);
         $q = "ALTER TABLE {$serendipity['dbPrefix']}categorytemplates ADD COLUMN pass varchar(255) default null";
         $sql = serendipity_db_schema_import($q);
         $this->set_config('dbversion', CATEGORYTEMPLATE_DB_VERSION);
     } elseif ($ver != CATEGORYTEMPLATE_DB_VERSION) {
         $q = "CREATE TABLE {$serendipity['dbPrefix']}categorytemplates (\n                        categoryid int(11) default null,\n                        template varchar(255) default null,\n                        fetchlimit int(4) default null,\n                        futureentries int(4) default null,\n                        lang varchar(255) default null,\n                        pass varchar(255) default null,\n                        sort_order varchar(255),\n                        hide_rss varchar(4) default null\n                    )";
         $sql = serendipity_db_schema_import($q);
         $q = "CREATE INDEX ctcid ON {$serendipity['dbPrefix']}categorytemplates (categoryid);";
         $sql = serendipity_db_schema_import($q);
         $this->set_config('dbversion', CATEGORYTEMPLATE_DB_VERSION);
     }
     return true;
 }
Пример #20
0
        }
    }
}
@uksort($sqlfiles, "strnatcasecmp");
if ($serendipity['GET']['action'] == 'ignore') {
    /* Todo: Don't know what to put here? */
} elseif ($serendipity['GET']['action'] == 'upgrade') {
    serendipity_smarty_purge();
    $errors = array();
    /* Install SQL files */
    foreach ($sqlfiles as $sqlfile) {
        $sql = file_get_contents(S9Y_INCLUDE_PATH . 'sql/' . $sqlfile);
        $sql = str_replace('{PREFIX}', $serendipity['dbPrefix'], $sql);
        preg_match_all("@(.*);@iUs", $sql, $res);
        foreach ($res[0] as $sql) {
            $r = serendipity_db_schema_import($sql);
            if (is_string($r)) {
                $errors[] = trim($r);
            }
        }
    }
    /* Call functions */
    $data['call_tasks'] = array();
    foreach ($tasks as $task) {
        if (!empty($task['function']) && version_compare($serendipity['versionInstalled'], $task['version'], '<')) {
            if (is_callable($task['function'])) {
                $data['is_callable_task'] = true;
                $data['call_tasks'][] = sprintf('Calling %s ...<br />', is_array($task['function']) ? $task['function'][0] . '::' . $task['function'][1] : $task['function']);
                if (empty($task['arguments'])) {
                    call_user_func($task['function']);
                } else {
 function generate_content(&$title)
 {
     global $serendipity;
     $title = $this->title;
     $reading = $this->get_config('reading');
     $reading_locale = $this->get_config('reading_locale');
     $listening_band = $this->get_config('listening_band');
     $listening_album = $this->get_config('listening_album');
     $listening_track = $this->get_config('listening_track');
     $listening_locale = $this->get_config('listening_locale');
     $playing = $this->get_config('playing');
     $playing_locale = $this->get_config('plaing_locale');
     $watching = $this->get_config('watching');
     $this->associates_tag = $this->get_config('associates_tag');
     $this->associates_id = $this->get_config('associates_id');
     $this->associates_key = $this->get_config('associates_key');
     // Create table, if its not there, or if we have a new version
     if ($this->get_config('version') != '1.01') {
         $q = "CREATE TABLE {$serendipity['dbPrefix']}currently (\n                        id {AUTOINCREMENT} {PRIMARY},\n                        search varchar(255) default NULL,\n                        section varchar(255) default NULL,\n                        detail text,\n                        url text\n                    )";
         $sql = serendipity_db_schema_import($q);
         //$results = serendipity_db_query($sql);
         $this->set_config('version', '1.01');
     }
     echo '<dl>';
     if ($reading != '') {
         print "<dt><strong>" . PLUGIN_CURRENTLY_READING . "</strong></dt><dd>{$reading}</dd>";
         $reading_image = $this->search_database($reading, 'Books', $reading_locale);
         if ($reading_image) {
             print "<dd><a href='{$reading_image['Detail']}'><img src='{$reading_image['Image']}'></a></dd>";
         }
     }
     //fi
     if ($listening_band != '') {
         print "<dt><strong>" . PLUGIN_CURRENTLY_LISTENING . "</strong></dt><dd>{$listening_band}</dd>";
         if ($listening_album) {
             print "<dd>({$listening_album})</dd>";
         }
         if ($listening_track) {
             print "<dd><em>{$listening_track}</em></dd>";
         }
         // The most reliable way to get the proper album cover off amazon is searching for "Artist - Album"
         // which is why I seperated everything out. Some people didnt mind putting everyting in one
         // text box, but some wanted the song title which messed up the query a lot, and some wanted just
         // the album and band displayed.
         $listen_search = "{$listening_band} - {$listening_album}";
         $listening_image = $this->search_database($listen_search, 'Music', $listening_locale);
         if ($listening_image) {
             print "<dd><a href='{$listening_image['Detail']}'><img src='{$listening_image['Image']}'></a></dd>";
         }
     }
     //fi
     if ($playing != '') {
         print "<dt><strong>" . PLUGIN_CURRENTLY_PLAYING . "</strong></dt>";
         print "<dd>{$playing}</dd>";
         $playing_image = $this->search_database($playing, 'VideoGames', $playing_locale);
         if ($playing_image) {
             print "<dd><a href='{$playing_image['Detail']}'><img src='{$playing_image['Image']}'></a></dd>";
         }
     }
     //fi
     if ($watching != '') {
         print "<dt><strong>" . PLUGIN_CURRENTLY_WATCHING . "</strong></dt><dd>{$watching}</dd>";
         $watching_image = $this->search_database($watching, 'Video', $watching_locale);
         if ($watching_image) {
             print "<dd><a href='{$watching_image['Detail']}'><img src='{$watching_image['Image']}'></a></dd>";
         }
     }
     //fi
     echo '</dl>';
 }
 static function static_install()
 {
     global $serendipity;
     if (!serendipity_event_freetag::tableCreated('entrytags')) {
         $q = "CREATE TABLE {$serendipity['dbPrefix']}entrytags (" . "entryid int(10) not null, " . "tag varchar(50) not null, " . "primary key (entryid, tag)" . ")";
         $result = serendipity_db_schema_import($q);
         if ($result !== true) {
             return;
         }
         serendipity_db_schema_import("CREATE INDEX tagsentryindex ON {$serendipity['dbPrefix']}entrytags (entryid)");
         serendipity_db_schema_import("CREATE INDEX tagsTagIndex ON {$serendipity['dbPrefix']}entrytags (tag)");
     }
     if (!serendipity_event_freetag::tableCreated('tagkeywords')) {
         $q = "CREATE TABLE {$serendipity['dbPrefix']}tagkeywords (" . "keywords text, " . "tag varchar(50) not null, " . "primary key (tag)" . ")";
         $result = serendipity_db_schema_import($q);
     }
     if (serendipity_event_freetag::upgradeFromVersion1()) {
         serendipity_event_freetag::convertEntryPropertiesTags();
     } else {
         echo "NOT UPGRADING!";
     }
 }
/**
 * Setup the core database tables
 *
 * Creates the needed tables - beware, they will be empty and need to be stuffed with
 * default templates and such...
 *
 * @access public
 * @return null
 */
function serendipity_installDatabase()
{
    global $serendipity;
    $queries = serendipity_parse_sql_tables(S9Y_INCLUDE_PATH . 'sql/db.sql');
    $queries = str_replace('{PREFIX}', $serendipity['dbPrefix'], $queries);
    foreach ($queries as $query) {
        serendipity_db_schema_import($query);
    }
    if (file_exists(S9Y_INCLUDE_PATH . 'sql/preload.sql')) {
        $queries = serendipity_parse_sql_inserts(S9Y_INCLUDE_PATH . 'sql/preload.sql');
        $queries = str_replace('{PREFIX}', $serendipity['dbPrefix'], $queries);
        foreach ($queries as $query) {
            serendipity_db_schema_import($query);
        }
    }
}
 /**
  * Updates database schema when upgrading from older versions.
  */
 function checkScheme()
 {
     global $serendipity;
     $version = $this->get_config('dbversion', '0');
     if ($version == "2.1") {
         $q = "ALTER TABLE {$serendipity['dbPrefix']}karmalog ADD votetime INT(11) default null";
         $sql = serendipity_db_schema_import($q);
         $this->set_config('dbversion', PLUGIN_KARMA_DB_VERSION);
     } elseif ($version == '2.0') {
         if (preg_match('@(postgres|pgsql)@i', $serendipity['dbType'])) {
             $q = "ALTER TABLE {$serendipity['dbPrefix']}karmalog ALTER COLUMN ip TYPE VARCHAR(45)";
         } else {
             $q = "ALTER TABLE {$serendipity['dbPrefix']}karmalog CHANGE COLUMN ip ip VARCHAR(45)";
         }
         $sql = serendipity_db_schema_import($q);
         $this->set_config('dbversion', PLUGIN_KARMA_DB_VERSION);
     } elseif ($version == '1.1') {
         $q = "ALTER TABLE {$serendipity['dbPrefix']}karma ADD visits INT(11) default 0";
         $sql = serendipity_db_schema_import($q);
         $this->set_config('dbversion', PLUGIN_KARMA_DB_VERSION);
     } elseif ($version == '1.0') {
         $q = "ALTER TABLE {$serendipity['dbPrefix']}karma ADD visits INT(11) default 0";
         $sql = serendipity_db_schema_import($q);
         $q = "CREATE TABLE {$serendipity['dbPrefix']}karmalog (\n                        entryid int(11) default null,\n                        points int(4) default null,\n                        ip varchar(45),\n                        user_agent varchar(255),\n                        votetime int(11) default null\n                    )";
         $sql = serendipity_db_schema_import($q);
         $this->set_config('dbversion', PLUGIN_KARMA_DB_VERSION);
     } elseif ($version != PLUGIN_KARMA_DB_VERSION) {
         $q = "CREATE TABLE {$serendipity['dbPrefix']}karma (\n                        entryid int(11) default null,\n                        points int(4) default null,\n                        votes int(4) default null,\n                        lastvote int(10) {UNSIGNED} NULL,\n                        visits int(11) default null\n                    )";
         $sql = serendipity_db_schema_import($q);
         $q = "CREATE TABLE {$serendipity['dbPrefix']}karmalog (\n                        entryid int(11) default null,\n                        points int(4) default null,\n                        ip varchar(45),\n                        user_agent varchar(255),\n                        votetime int(11) default null\n                    )";
         $sql = serendipity_db_schema_import($q);
         $q = "CREATE INDEX kfetch ON {$serendipity['dbPrefix']}karma (entryid, lastvote);";
         $sql = serendipity_db_schema_import($q);
         $q = "CREATE INDEX kentryid ON {$serendipity['dbPrefix']}karma (entryid);";
         $sql = serendipity_db_schema_import($q);
         $this->set_config('dbversion', PLUGIN_KARMA_DB_VERSION);
     }
     return true;
 }
    function generate_content(&$title)
    {
        global $serendipity;
        $title = $this->title;
        $max_entries = $this->get_config('max_entries');
        $max_chars = $this->get_config('max_chars');
        $wordwrap = $this->get_config('wordwrap');
        $dateformat = $this->get_config('dateformat');
        $box_cols = $this->get_config('box_cols');
        $box_rows = $this->get_config('box_rows');
        // Create table, if not yet existant
        if ($this->get_config('version') != '1.0') {
            $q = "CREATE TABLE {$serendipity['dbPrefix']}shoutbox (\n                        id {AUTOINCREMENT} {PRIMARY},\n                        timestamp int(10) {UNSIGNED} NULL,\n                        ip varchar(15) default NULL,\n                        body text\n                    )";
            $sql = serendipity_db_schema_import($q);
            $this->set_config('version', '1.0');
        }
        //Put new shout into the database if necessary
        if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'fillshoutbox' && $_REQUEST['serendipity']['shouttext'] != '') {
            $sql = sprintf("INSERT INTO %sshoutbox (\n                            timestamp,\n                            ip,\n                            body\n                       ) VALUES (\n                            %s,\n                            '%s',\n                            '%s'\n                       )", $serendipity['dbPrefix'], time(), serendipity_db_escape_string($_SERVER['REMOTE_ADDR']), serendipity_db_escape_string($_REQUEST['serendipity']['shouttext']));
            serendipity_db_query($sql);
        }
        if (!empty($serendipity['GET']['action']) && $serendipity['GET']['action'] == 'shoutboxdelete' && $_SESSION['serendipityAuthedUser'] === true) {
            $sql = sprintf("DELETE from %sshoutbox\n                              WHERE id = %d", $serendipity['dbPrefix'], (int) $serendipity['GET']['comment_id']);
            serendipity_db_query($sql);
        }
        if (!$max_entries || !is_numeric($max_entries) || $max_entries < 1) {
            $max_entries = 15;
        }
        if (!$max_chars || !is_numeric($max_chars) || $max_chars < 1) {
            $max_chars = 120;
        }
        if (!$wordwrap || !is_numeric($wordwrap) || $wordwrap < 1) {
            $wordwrap = 30;
        }
        if (!$dateformat || strlen($dateformat) < 1) {
            $dateformat = '%a, %d.%m.%Y %H:%M';
        }
        if (!$box_cols || !is_numeric($box_cols) || $box_cols < 1) {
            $box_cols = 15;
        }
        if (!$box_rows || !is_numeric($box_rows) || $box_rows < 1) {
            $box_rows = 4;
        }
        ?>
       <form action="<?php 
        echo serendipity_currentURL(true);
        ?>
" method="post">
           <input type="hidden" name="action" value="fillshoutbox" />
           <textarea name="serendipity[shouttext]" rows="<?php 
        echo $box_rows;
        ?>
" cols="<?php 
        echo $box_cols;
        ?>
" style="width: 90%"></textarea>
           <input name='submit' type='submit' value='<?php 
        echo PLUGIN_SHOUTBOX_SUBMIT;
        ?>
' />
       </form>
<?php 
        $q = 'SELECT    s.body              AS comment,
                        s.timestamp         AS stamp,
                        s.id                AS comment_id
                FROM    ' . $serendipity['dbPrefix'] . 'shoutbox AS s
            ORDER BY    s.timestamp DESC
               LIMIT ' . $max_entries;
        ?>
<div class="serendipity_shoutbox">
<?php 
        $sql = serendipity_db_query($q);
        if ($sql && is_array($sql)) {
            foreach ($sql as $key => $row) {
                $comments = wordwrap(strip_tags($row['comment']), $max_chars, '@@@', 1);
                $aComment = explode('@@@', $comments);
                $comment = $aComment[0];
                if (count($aComment) > 1) {
                    $comment .= ' [...]';
                }
                $deleteLink = "";
                if ($_SESSION['serendipityAuthedUser'] === true) {
                    $deleteLink = '<a href="' . $serendipity['baseURL'] . '?serendipity[action]=shoutboxdelete&amp;serendipity[comment_id]=' . $row['comment_id'] . '">' . PLUGIN_SHOUTBOX_DELETE . '</a>';
                }
                $entry = array('comment' => $comment);
                serendipity_plugin_api::hook_event('frontend_display', $entry);
                $entry['comment'] = wordwrap($entry['comment'], $wordwrap, "\n", 1);
                echo '<div class="serendipity_shoutbox_date">' . htmlspecialchars(serendipity_strftime($dateformat, $row['stamp'])) . '</div>' . "\n" . '<div class="serendipity_shoutbox_comment">' . $entry['comment'] . '</div>' . "\n" . '<div class="serendipity_shoutbox_delete">' . $deleteLink . '</div>' . "\n\n";
            }
        }
        ?>
</div>
<?php 
    }
 /**
  * Log spam to database
  * @param  string $id
  * @param  string $switch
  * @param  string $reason
  * @param  string $addData
  */
 function spamlog($id, $switch, $reason, $addData)
 {
     global $serendipity;
     $method = $this->get_config('spamlogtype', 'none');
     $logfile = $this->get_config('spamlogfile', $serendipity['serendipityPath'] . 'spamblock.log');
     switch ($method) {
         case 'file':
             if (empty($logfile)) {
                 return;
             }
             if (strpos($logfile, '%') !== false) {
                 $logfile = strftime($logfile);
             }
             $fp = @fopen($logfile, 'a+');
             if (!is_resource($fp)) {
                 return;
             }
             fwrite($fp, sprintf('[%s] - [%s: %s] - [#%s, Name "%s", E-Mail "%s", URL "%s", User-Agent "%s", IP %s] - [%s]' . "\n", date('Y-m-d H:i:s', serendipity_serverOffsetHour()), $switch, $reason, $id, str_replace("\n", ' ', $addData['name']), str_replace("\n", ' ', $addData['email']), str_replace("\n", ' ', $addData['url']), str_replace("\n", ' ', $_SERVER['HTTP_USER_AGENT']), $_SERVER['REMOTE_ADDR'], str_replace("\n", ' ', $addData['comment'])));
             fclose($fp);
             break;
         case 'none':
             return;
             break;
         case 'db':
         default:
             $reason = serendipity_db_escape_string($reason);
             $q = sprintf("INSERT INTO {$serendipity['dbPrefix']}spamblocklog\n                                          (timestamp, type, reason, entry_id, author, email, url,  useragent, ip,   referer, body)\n                                   VALUES (%d,        '%s',  '%s',  '%s',     '%s',   '%s',  '%s', '%s',      '%s', '%s',    '%s')", serendipity_serverOffsetHour(), serendipity_db_escape_string($switch), serendipity_db_escape_string($reason), serendipity_db_escape_string($id), serendipity_db_escape_string($addData['name']), serendipity_db_escape_string($addData['email']), serendipity_db_escape_string($addData['url']), substr(serendipity_db_escape_string($_SERVER['HTTP_USER_AGENT']), 0, 255), serendipity_db_escape_string($_SERVER['REMOTE_ADDR']), substr(serendipity_db_escape_string(isset($_SESSION['HTTP_REFERER']) ? $_SESSION['HTTP_REFERER'] : $_SERVER['HTTP_REFERER']), 0, 255), serendipity_db_escape_string($addData['comment']));
             serendipity_db_schema_import($q);
             break;
     }
 }
 function setupDB()
 {
     global $serendipity;
     $db = $this->get_config('db_built', 0);
     switch ($db) {
         case 0:
             $q = 'CREATE TABLE ' . $serendipity['dbPrefix'] . 'faqs (
                     id {AUTOINCREMENT} {PRIMARY},
                     cid int(11) default 0,
                     faqorder int(11) default 0,
                     question text,
                     answer text
             ) {UTF_8}';
             serendipity_db_schema_import($q);
             $q = "CREATE TABLE " . $serendipity['dbPrefix'] . "faq_categorys (\n                        id {AUTOINCREMENT} {PRIMARY},\n                        parent_id int(11) not null default 0,\n                        catorder int(11) default 0,\n                        category varchar(255) not null,\n                        introduction text\n                ) {UTF_8}";
             serendipity_db_schema_import($q);
         case 1:
             $q = 'ALTER TABLE ' . $serendipity['dbPrefix'] . 'faqs ADD COLUMN changedate int(11) default 0';
             serendipity_db_schema_import($q);
             $q = 'ALTER TABLE ' . $serendipity['dbPrefix'] . 'faqs ADD COLUMN changetype varchar(10)';
             serendipity_db_schema_import($q);
         case 2:
             $q = 'CREATE {FULLTEXT_MYSQL} INDEX faqentry_idx on ' . $serendipity['dbPrefix'] . 'faqs (question, answer)';
             serendipity_db_schema_import($q);
         case 3:
             $q = 'ALTER TABLE ' . $serendipity['dbPrefix'] . 'faq_categorys ADD COLUMN language varchar(2)';
             serendipity_db_schema_import($q);
             serendipity_db_update('faq_categorys', array(), array('language' => $serendipity['language']));
             $this->set_config('db_built', 4);
             break;
     }
 }
Пример #28
0
 /**
  * Updates database schema when upgrading from older versions.
  */
 function checkScheme()
 {
     global $serendipity;
     $version = $this->get_config('dbversion', '0');
     if ($version == '1.1') {
         $q = "ALTER TABLE {$serendipity['dbPrefix']}karma ADD visits INT(11) default 0";
         $sql = serendipity_db_schema_import($q);
         $this->set_config('dbversion', PLUGIN_KARMA_DB_VERSION);
     } elseif ($version == '1.0') {
         $q = "ALTER TABLE {$serendipity['dbPrefix']}karma ADD visits INT(11) default 0";
         $sql = serendipity_db_schema_import($q);
         $q = "CREATE TABLE {$serendipity['dbPrefix']}karmalog (\n                        entryid int(11) default null,\n                        points int(4) default null,\n                        ip varchar(15),\n                        user_agent varchar(255),\n                        votetime int(11) default null\n                    )";
         $sql = serendipity_db_schema_import($q);
         $this->set_config('dbversion', PLUGIN_KARMA_DB_VERSION);
     } elseif ($version != PLUGIN_KARMA_DB_VERSION) {
         $q = "CREATE TABLE {$serendipity['dbPrefix']}karma (\n                        entryid int(11) default null,\n                        points int(4) default null,\n                        votes int(4) default null,\n                        lastvote int(10) {UNSIGNED} NULL,\n                        visits int(11) default null\n                    )";
         $sql = serendipity_db_schema_import($q);
         $q = "CREATE TABLE {$serendipity['dbPrefix']}karmalog (\n                        entryid int(11) default null,\n                        points int(4) default null,\n                        ip varchar(15),\n                        user_agent varchar(255),\n                        votetime int(11) default null\n                    )";
         $sql = serendipity_db_schema_import($q);
         $q = "CREATE INDEX kfetch ON {$serendipity['dbPrefix']}karma (entryid, lastvote);";
         $sql = serendipity_db_schema_import($q);
         $q = "CREATE INDEX kentryid ON {$serendipity['dbPrefix']}karma (entryid);";
         $sql = serendipity_db_schema_import($q);
         $this->set_config('dbversion', PLUGIN_KARMA_DB_VERSION);
     }
     return true;
 }
 function checkScheme()
 {
     global $serendipity;
     $dbversion = $this->get_config('dbversion', '1');
     if ($dbversion == '1') {
         $q = "CREATE TABLE {$serendipity['dbPrefix']}spamblocklog (\n                        timestamp int(10) {UNSIGNED} default null,\n                        type varchar(255),\n                        reason text,\n                        entry_id int(10) {UNSIGNED} not null default '0',\n                        author varchar(80),\n                        email varchar(200),\n                        url varchar(200),\n                        useragent varchar(255),\n                        ip varchar(45),\n                        referer varchar(255),\n                        body text)";
         $sql = serendipity_db_schema_import($q);
         $q = "CREATE INDEX kspamidx ON {$serendipity['dbPrefix']}spamblocklog (timestamp);";
         $sql = serendipity_db_schema_import($q);
         $q = "CREATE INDEX kspamtypeidx ON {$serendipity['dbPrefix']}spamblocklog (type);";
         $sql = serendipity_db_schema_import($q);
         $q = "CREATE INDEX kspamentryidx ON {$serendipity['dbPrefix']}spamblocklog (entry_id);";
         $sql = serendipity_db_schema_import($q);
         $q = "CREATE TABLE {$serendipity['dbPrefix']}spamblock_htaccess (\n                        timestamp int(10) {UNSIGNED} default null,\n                        ip varchar(15))";
         $sql = serendipity_db_schema_import($q);
         $q = "CREATE INDEX kshtaidx ON {$serendipity['dbPrefix']}spamblock_htaccess (timestamp);";
         $sql = serendipity_db_schema_import($q);
         $this->set_config('dbversion', '3');
     }
     if ($dbversion == '2') {
         if (preg_match('@(postgres|pgsql)@i', $serendipity['dbType'])) {
             $q = "ALTER TABLE {$serendipity['dbPrefix']}spamblocklog ALTER COLUMN ip TYPE VARCHAR(45)";
             $sql = serendipity_db_schema_import($q);
             $q = "ALTER TABLE {$serendipity['dbPrefix']}spamblock_htaccess ALTER COLUMN ip TYPE VARCHAR(45)";
             $sql = serendipity_db_schema_import($q);
         } else {
             $q = "ALTER TABLE {$serendipity['dbPrefix']}spamblocklog CHANGE COLUMN ip ip VARCHAR(45)";
             $sql = serendipity_db_schema_import($q);
             $q = "ALTER TABLE {$serendipity['dbPrefix']}spamblock_htaccess CHANGE COLUMN ip ip VARCHAR(45)";
             $sql = serendipity_db_schema_import($q);
         }
         $this->set_config('dbversion', '3');
     }
     return true;
 }
 function setupDB()
 {
     global $serendipity;
     # Old Schema
     if (!serendipity_db_bool($this->get_config('db_built', false))) {
         $sql = "CREATE TABLE {$serendipity['dbPrefix']}aggregator_feeds (\n                          feedid {AUTOINCREMENT} {PRIMARY},\n                          feedname    varchar(255) NOT NULL default '',\n                          feedurl     varchar(255) NOT NULL default '',\n                          htmlurl     varchar(255) NOT NULL default '',\n                          categoryid  int(11) default NULL,\n                          last_update int(10) {UNSIGNED} default null,\n                          charset     varchar(255) NOT NULL default ''\n                        );";
         serendipity_db_schema_import($sql);
         $this->set_config('db_built', 'true');
     }
     # Schema extension (version 2)
     if ($this->get_config('db_version') < 2) {
         echo "*** setup DB version " . $this->get_config('db_version') . "<br />\n";
         $sql = "CREATE TABLE {$serendipity['dbPrefix']}aggregator_md5 (\n                          entryid {AUTOINCREMENT} {PRIMARY},\n                          md5         varchar(32) NOT NULL default '',\n                          timestamp   int(10) {UNSIGNED} default null,\n                          key md5_idx (md5),\n                          key timestamp_idx (timestamp)\n                        );";
         serendipity_db_schema_import($sql);
         $sql = "INSERT INTO {$serendipity['dbPrefix']}aggregator_md5\n                        ( entryid, md5, timestamp )\n                        SELECT entryid, value, " . time() . " FROM {$serendipity['dbPrefix']}entryproperties\n                        WHERE property = 'ep_aggregator_md5'";
         serendipity_db_query($sql);
         $sql = "DELETE FROM {$serendipity['dbPrefix']}entryproperties\n                    WHERE property = 'ep_aggregator_md5'";
         serendipity_db_query($sql);
         $this->set_config('db_version', '2');
     }
     # Schema extension (version 3)
     if ($this->get_config('db_version') < 3) {
         echo "*** setup DB version " . $this->get_config('db_version') . "<br />\n";
         $sql = "CREATE TABLE {$serendipity['dbPrefix']}aggregator_feedcat (\n                         feedid int(11) not null,\n                         categoryid int(11) not null\n                        );";
         serendipity_db_schema_import($sql);
         $sql = "CREATE UNIQUE INDEX feedid_idx\n                        ON {$serendipity['dbPrefix']}aggregator_feedcat (feedid, categoryid);";
         serendipity_db_schema_import($sql);
         $sql = "INSERT INTO {$serendipity['dbPrefix']}aggregator_feedcat\n                        ( feedid, categoryid  )\n                        SELECT feedid, categoryid\n                        FROM {$serendipity['dbPrefix']}aggregator_feeds";
         serendipity_db_query($sql);
         $sql = "DELETE FROM {$serendipity['dbPrefix']}entryproperties\n                    WHERE property = 'ep_aggregator_md5'";
         serendipity_db_query($sql);
         $sql = "ALTER TABLE {$serendipity['dbPrefix']}aggregator_feeds\n                          DROP categoryid;";
         serendipity_db_schema_import($sql);
         $this->set_config('db_version', '3');
     }
     # Schema extension (version 4)
     if ($this->get_config('db_version') < 4) {
         $sql = "ALTER TABLE {$serendipity['dbPrefix']}aggregator_feeds\n                          ADD COLUMN charset varchar(255);";
         serendipity_db_schema_import($sql);
         $this->set_config('db_version', '4');
     }
     # Schema extension (version 5)
     if ($this->get_config('db_version') < 5) {
         $sql = "ALTER TABLE {$serendipity['dbPrefix']}aggregator_feeds\n                          ADD COLUMN match_expression varchar(255);";
         serendipity_db_schema_import($sql);
         $this->set_config('db_version', '5');
     }
     # Schema extension (version 6)
     if ($this->get_config('db_version') < 6) {
         $sql = "CREATE TABLE {$serendipity['dbPrefix']}aggregator_feedlist (\n                         id {AUTOINCREMENT} {PRIMARY},\n                         feedid int(11) not null,\n                         categoryid int(11) not null,\n                         entrydate int(11) not null,\n                         entrytitle text,\n                         entrybody longtext,\n                         entryurl text\n                        );";
         serendipity_db_schema_import($sql);
         $sql = "ALTER TABLE {$serendipity['dbPrefix']}aggregator_feeds\n                          ADD COLUMN feedicon text;";
         serendipity_db_schema_import($sql);
         $this->set_config('db_version', '6');
     }
     if ($this->get_config('db_version') < 7) {
         $sql = "CREATE INDEX fl_feedid ON {$serendipity['dbPrefix']}aggregator_feedlist (feedid)";
         serendipity_db_schema_import($sql);
         $sql = "CREATE INDEX fl_entrydate ON {$serendipity['dbPrefix']}aggregator_feedlist (entrydate)";
         serendipity_db_schema_import($sql);
         $sql = "CREATE INDEX fl_categoryid ON {$serendipity['dbPrefix']}aggregator_feedlist (categoryid)";
         serendipity_db_schema_import($sql);
         $sql = "CREATE INDEX fl_feedid_2 ON {$serendipity['dbPrefix']}aggregator_feedlist (feedid, entrydate)";
         serendipity_db_schema_import($sql);
         $sql = "CREATE INDEX fl_feedid_3 ON {$serendipity['dbPrefix']}aggregator_feedlist (feedid, entrydate, categoryid)";
         serendipity_db_schema_import($sql);
         $this->set_config('db_version', '7');
     }
 }