| 1 | <?php |
|---|
| 2 | /*********************************************************************** |
|---|
| 3 | |
|---|
| 4 | FluxBB extension |
|---|
| 5 | Portal |
|---|
| 6 | Daris <daris91@gmail.com> |
|---|
| 7 | |
|---|
| 8 | ************************************************************************/ |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | // Make sure no one attempts to run this script "directly" |
|---|
| 12 | if (!defined('FORUM')) |
|---|
| 13 | exit; |
|---|
| 14 | |
|---|
| 15 | function install() |
|---|
| 16 | { |
|---|
| 17 | global $forum_db; |
|---|
| 18 | |
|---|
| 19 | // it's an upgrade |
|---|
| 20 | if (defined('EXT_CUR_VERSION')) |
|---|
| 21 | { |
|---|
| 22 | // do upgrade... |
|---|
| 23 | if (EXT_CUR_VERSION == '1.0') |
|---|
| 24 | { |
|---|
| 25 | $forum_db->add_field('downloads', 'file', 'VARCHAR(255)', false); |
|---|
| 26 | |
|---|
| 27 | $query = array( |
|---|
| 28 | 'SELECT' => 'name, version, id', |
|---|
| 29 | 'FROM' => 'downloads', |
|---|
| 30 | ); |
|---|
| 31 | $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); |
|---|
| 32 | |
|---|
| 33 | while ($cur_download = $forum_db->fetch_assoc($result)) |
|---|
| 34 | { |
|---|
| 35 | $version = ($cur_download['version'] != '' ? '_'.$cur_download['version'] : ''); |
|---|
| 36 | $filename = $cur_download['name'].$version.'.zip'; |
|---|
| 37 | $filename = str_replace(' ', '_', strtolower($filename)); |
|---|
| 38 | $filename = preg_replace('/[^0-9a-z\._]/', '', $filename); |
|---|
| 39 | |
|---|
| 40 | $query2 = array( |
|---|
| 41 | 'UPDATE' => 'downloads', |
|---|
| 42 | 'SET' => 'file=\''.$forum_db->escape($filename).'\'', |
|---|
| 43 | 'WHERE' => 'id=\''.$cur_download['id'].'\'', |
|---|
| 44 | ); |
|---|
| 45 | $result2 = $forum_db->query_build($query2) or error(__FILE__, __LINE__); |
|---|
| 46 | |
|---|
| 47 | rename(FORUM_ROOT.'extensions/download/files/'.$cur_download['id'].'.zip', FORUM_ROOT.'extensions/download/files/'.$filename); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | } |
|---|
| 53 | // it's a fresh install |
|---|
| 54 | else |
|---|
| 55 | { |
|---|
| 56 | |
|---|
| 57 | // Table panels |
|---|
| 58 | $schema = array( |
|---|
| 59 | 'FIELDS' => array( |
|---|
| 60 | 'id' => array( |
|---|
| 61 | 'datatype' => 'SERIAL', |
|---|
| 62 | 'allow_null' => false |
|---|
| 63 | ), |
|---|
| 64 | 'name' => array( |
|---|
| 65 | 'datatype' => 'VARCHAR(255)', |
|---|
| 66 | 'allow_null' => true |
|---|
| 67 | ), |
|---|
| 68 | 'description' => array( |
|---|
| 69 | 'datatype' => 'text', |
|---|
| 70 | 'allow_null' => true |
|---|
| 71 | ), |
|---|
| 72 | ), |
|---|
| 73 | 'PRIMARY KEY' => array('id') |
|---|
| 74 | ); |
|---|
| 75 | |
|---|
| 76 | $forum_db->create_table('downloads_cats', $schema); |
|---|
| 77 | $forum_db->query('INSERT INTO '.$forum_db->prefix.'downloads_cats (name) VALUES (\'Rozszerzenia\')') or error(__FILE__, __LINE__); |
|---|
| 78 | $cat_id = $forum_db->insert_id(); |
|---|
| 79 | $forum_db->query('INSERT INTO '.$forum_db->prefix.'downloads_cats (name) VALUES (\'Style\')') or error(__FILE__, __LINE__); |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | // Table panels |
|---|
| 83 | $schema = array( |
|---|
| 84 | 'FIELDS' => array( |
|---|
| 85 | 'id' => array( |
|---|
| 86 | 'datatype' => 'SERIAL', |
|---|
| 87 | 'allow_null' => false |
|---|
| 88 | ), |
|---|
| 89 | 'cat' => array( |
|---|
| 90 | 'datatype' => 'INT(10) UNSIGNED', |
|---|
| 91 | 'allow_null' => true, |
|---|
| 92 | 'default' => $cat_id |
|---|
| 93 | ), |
|---|
| 94 | 'name' => array( |
|---|
| 95 | 'datatype' => 'VARCHAR(255)', |
|---|
| 96 | 'allow_null' => true |
|---|
| 97 | ), |
|---|
| 98 | 'description' => array( |
|---|
| 99 | 'datatype' => 'text', |
|---|
| 100 | 'allow_null' => true |
|---|
| 101 | ), |
|---|
| 102 | 'version' => array( |
|---|
| 103 | 'datatype' => 'VARCHAR(255)', |
|---|
| 104 | 'allow_null' => true, |
|---|
| 105 | 'default' => '1.0' |
|---|
| 106 | ), |
|---|
| 107 | 'author' => array( |
|---|
| 108 | 'datatype' => 'VARCHAR(255)', |
|---|
| 109 | 'allow_null' => true, |
|---|
| 110 | ), |
|---|
| 111 | /* 'file' => array( |
|---|
| 112 | 'datatype' => 'VARCHAR(255)', |
|---|
| 113 | 'allow_null' => true |
|---|
| 114 | ),*/ |
|---|
| 115 | 'downloads' => array( |
|---|
| 116 | 'datatype' => 'INT(10) UNSIGNED', |
|---|
| 117 | 'allow_null' => true, |
|---|
| 118 | 'default' => 0 |
|---|
| 119 | ), |
|---|
| 120 | 'approved' => array( |
|---|
| 121 | 'datatype' => 'INT(1) UNSIGNED', |
|---|
| 122 | 'allow_null' => true, |
|---|
| 123 | 'default' => 0 |
|---|
| 124 | ), |
|---|
| 125 | 'user_id' => array( |
|---|
| 126 | 'datatype' => 'INT(10) UNSIGNED', |
|---|
| 127 | 'allow_null' => true, |
|---|
| 128 | ), |
|---|
| 129 | 'added' => array( |
|---|
| 130 | 'datatype' => 'INT(10) UNSIGNED', |
|---|
| 131 | 'allow_null' => true, |
|---|
| 132 | ), |
|---|
| 133 | ), |
|---|
| 134 | 'PRIMARY KEY' => array('id') |
|---|
| 135 | ); |
|---|
| 136 | |
|---|
| 137 | $forum_db->create_table('downloads', $schema); |
|---|
| 138 | $forum_db->query('INSERT INTO '.$forum_db->prefix.'downloads (name, description, approved) VALUES (\'Geshi highlight\', \'test\', 1)') or error(__FILE__, __LINE__); |
|---|
| 139 | |
|---|
| 140 | /* for ($i = 1; $i < 20; $i++) |
|---|
| 141 | $forum_db->query('INSERT INTO '.$forum_db->prefix.'downloads (name, description, approved) VALUES (\'Extension '.$i.'\', \'test\', 1)') or error(__FILE__, __LINE__);*/ |
|---|
| 142 | |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | function uninstall() |
|---|
| 148 | { |
|---|
| 149 | global $forum_db; |
|---|
| 150 | |
|---|
| 151 | $forum_db->drop_table('downloads_cats'); |
|---|
| 152 | $forum_db->drop_table('downloads'); |
|---|
| 153 | } |
|---|