3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2009 The Nucleus Group
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * (see nucleus/documentation/index.html#license for more info)
13 * @license http://nucleuscms.org/license.txt GNU General Public License
14 * @copyright Copyright (C) 2002-2009 The Nucleus Group
15 * @version $Id: upgrade0.96.php 1809 2012-05-01 14:48:30Z sakamocchi $
18 function upgrade_do96() {
20 if (upgrade_checkinstall(96))
21 return "already installed";
23 // 1. create nucleus_actionlog
24 if (!upgrade_checkIfTableExists('actionlog')) {
25 $query = 'CREATE TABLE '.sql_table('actionlog')." (timestamp datetime NOT NULL default '0000-00-00 00:00:00', message varchar(255) NOT NULL default '', PRIMARY KEY (timestamp)) ENGINE=MyISAM;";
26 upgrade_query("Creating nucleus_actionlog table",$query);
29 // 2. create nucleus_ban
30 if (!upgrade_checkIfTableExists('ban')) {
31 $query = 'CREATE TABLE '.sql_table('ban')." ( iprange varchar(15) NOT NULL default '', reason varchar(255) NOT NULL default '', blogid int(11) NOT NULL default '0') ENGINE=MyISAM;";
32 upgrade_query("Creating nucleus_ban table",$query);
35 // 3. add ikarma to nucleus_item
36 if (!upgrade_checkIfColumnExists('item','ikarma')) {
37 $query = 'ALTER TABLE '.sql_table('item')
38 . " ADD ikarma int(11) NOT NULL default '0'";
39 upgrade_query("Adding karma-votes to items",$query);
42 // 4. create nucleus_karma
43 if (!upgrade_checkIfTableExists('karma')) {
44 $query = 'CREATE TABLE '.sql_table('karma')." ("
45 ." itemid int(11) NOT NULL default '0',"
46 ." ip char(15) NOT NULL default ''"
48 upgrade_query("Creating nucleus_karma table",$query);
51 // 5. nucleus_config: add MediaURL, AllowedTypes, AllowLoginEdit, AllowUpload
53 // create MediaURL out of IndexURL
54 $mediaURL = $CONF['IndexURL'] . "media/";
56 if (!upgrade_checkIfCVExists('MediaURL')) {
57 $query = 'INSERT INTO '.sql_table('config')." VALUES ('MediaURL', '$mediaURL');";
58 upgrade_query("New setting MediaURL",$query);
60 if (!upgrade_checkIfCVExists('AllowedTypes')) {
61 $query = 'INSERT INTO '.sql_table('config')." VALUES ('AllowedTypes', 'jpg,jpeg,gif,mpg,mpeg,avi,mov,mp3,swf,png');";
62 upgrade_query("New setting AllowedTypes",$query);
64 if (!upgrade_checkIfCVExists('AllowLoginEdit')) {
65 $query = 'INSERT INTO '.sql_table('config')." VALUES ('AllowLoginEdit', '0');";
66 upgrade_query("New setting AllowLoginEdit",$query);
68 if (!upgrade_checkIfCVExists('AllowUpload')) {
69 $query = 'INSERT INTO '.sql_table('config')." VALUES ('AllowUpload', '1');";
70 upgrade_query("New setting AllowUpload",$query);
73 //The following blocks (6 and 7) should check for existing values and only update as needed.
74 // 6. add 'imagepopup' skincontents in skin 'default'
76 $query = 'SELECT sdnumber FROM '.sql_table('skin_desc')." WHERE sdname='default'";
77 $res = DB::getValue($query);
78 $query = 'INSERT INTO '.sql_table('skin')." VALUES (" . $res . ", 'imagepopup', '<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n <title><%imagetext%></title>\r\n <style type=\"text/css\">\r\n img { border: none; }\r\n </style>\r\n</head>\r\n<body>\r\n <a href=\"javascript:window.close();\"><%image%></a>\r\n</body>\r\n</html>');";
79 upgrade_query("Adding 'imagepopup' skinparts",$query);
81 // 7. add POPUP_CODE, MEDIA_CODE, IMAGE_CODE to ALL templates
82 $query = 'SELECT tdnumber FROM '.sql_table('template_desc');
83 $res = DB::getResult($query); // get all template ids
84 foreach ( $res as $row ) {
85 $tid = $row['tdnumber']; // template id
87 $query = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'POPUP_CODE', '<%popuplink%>');";
88 $query2 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'MEDIA_CODE', '<%media%>');";
89 $query3 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'IMAGE_CODE', '<%image%>');";
90 upgrade_query("Adding popupcode to template $tid",$query);
91 upgrade_query("Adding mediacode to template $tid",$query2);
92 upgrade_query("Adding imagecode to template $tid",$query3);
96 // 8. add cip to nucleus_comment
97 if(0==$upgrade_failures && !upgrade_checkIfColumnExists('comment', 'cip')){
98 $query = 'ALTER TABLE '.sql_table('comment')
99 . " ADD cip varchar(15) NOT NULL default ''";
100 upgrade_query("Adding IP attribute to comments",$query);
102 echo "<li>Adding IP attribute to comments ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";