[3673] | 1 | <?php |
---|
[23037] | 2 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
[3673] | 3 | |
---|
| 4 | if (!defined("COMMUNITY_PATH")) |
---|
| 5 | { |
---|
| 6 | define('COMMUNITY_PATH', PHPWG_PLUGINS_PATH.basename(dirname(__FILE__))); |
---|
| 7 | } |
---|
| 8 | |
---|
[23037] | 9 | include_once(COMMUNITY_PATH.'/include/install.inc.php'); |
---|
| 10 | |
---|
[3673] | 11 | function plugin_install() |
---|
| 12 | { |
---|
[23037] | 13 | community_install(); |
---|
| 14 | define('community_installed', true); |
---|
[3673] | 15 | } |
---|
| 16 | |
---|
| 17 | function plugin_uninstall() |
---|
| 18 | { |
---|
[9372] | 19 | global $prefixeTable; |
---|
| 20 | |
---|
| 21 | $query = 'DROP TABLE '.$prefixeTable.'community_permissions;'; |
---|
[3673] | 22 | pwg_query($query); |
---|
[9372] | 23 | |
---|
| 24 | $query = 'DROP TABLE '.$prefixeTable.'community_pendings;'; |
---|
| 25 | pwg_query($query); |
---|
[23085] | 26 | |
---|
| 27 | $query = 'ALTER TABLE '.$prefixeTable.'categories drop column community_user;'; |
---|
| 28 | pwg_query($query); |
---|
| 29 | |
---|
| 30 | // delete configuration |
---|
| 31 | pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param IN ("community", "community_cache_key");'); |
---|
[3673] | 32 | } |
---|
[9539] | 33 | |
---|
| 34 | function plugin_activate() |
---|
| 35 | { |
---|
[9566] | 36 | global $prefixeTable; |
---|
[10773] | 37 | |
---|
[23037] | 38 | if (!defined('community_installed')) // a plugin is activated just after its installation |
---|
[10773] | 39 | { |
---|
[23037] | 40 | community_install(); |
---|
[10773] | 41 | } |
---|
| 42 | |
---|
[9539] | 43 | community_get_data_from_core21(); |
---|
| 44 | community_get_data_from_community21(); |
---|
[9566] | 45 | |
---|
| 46 | $query = ' |
---|
| 47 | SELECT |
---|
| 48 | COUNT(*) |
---|
| 49 | FROM '.$prefixeTable.'community_permissions |
---|
| 50 | ;'; |
---|
| 51 | list($counter) = pwg_db_fetch_row(pwg_query($query)); |
---|
| 52 | if (0 == $counter) |
---|
| 53 | { |
---|
| 54 | community_create_default_permission(); |
---|
| 55 | } |
---|
[9585] | 56 | |
---|
| 57 | include_once(dirname(__FILE__).'/include/functions_community.inc.php'); |
---|
| 58 | community_update_cache_key(); |
---|
[9539] | 59 | } |
---|
| 60 | |
---|
| 61 | function community_get_data_from_core21() |
---|
| 62 | { |
---|
| 63 | global $conf, $prefixeTable; |
---|
| 64 | |
---|
[21289] | 65 | $from_piwigo21_file = $conf['data_location'].'/plugins/core_user_upload_to_community.php'; |
---|
[9539] | 66 | if (is_file($from_piwigo21_file)) |
---|
| 67 | { |
---|
| 68 | include($from_piwigo21_file); |
---|
| 69 | $user_upload_conf = unserialize($user_upload_conf); |
---|
| 70 | |
---|
| 71 | $user_upload_conf['upload_user_access'] = 1; |
---|
| 72 | |
---|
| 73 | if (isset($user_upload_conf['uploadable_categories']) and is_array($user_upload_conf['uploadable_categories'])) |
---|
| 74 | { |
---|
| 75 | $type = 'any_registered_user'; |
---|
| 76 | if (isset($user_upload_conf['upload_user_access']) and 1 == $user_upload_conf['upload_user_access']) |
---|
| 77 | { |
---|
| 78 | $type = 'any_visitor'; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | $inserts = array(); |
---|
| 82 | |
---|
| 83 | foreach ($user_upload_conf['uploadable_categories'] as $category_id) |
---|
| 84 | { |
---|
| 85 | array_push( |
---|
| 86 | $inserts, |
---|
| 87 | array( |
---|
| 88 | 'type' => $type, |
---|
| 89 | 'category_id' => $category_id, |
---|
| 90 | 'recursive' => 'false', |
---|
| 91 | 'create_subcategories' => 'false', |
---|
| 92 | 'moderated' => 'true', |
---|
| 93 | ) |
---|
| 94 | ); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | if (count($inserts) > 0) |
---|
| 98 | { |
---|
| 99 | mass_inserts( |
---|
| 100 | $prefixeTable.'community_permissions', |
---|
| 101 | array_keys($inserts[0]), |
---|
| 102 | $inserts |
---|
| 103 | ); |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | if (isset($user_upload_conf['waiting_rows']) and is_array($user_upload_conf['waiting_rows'])) |
---|
| 108 | { |
---|
| 109 | $id_of_user = array(); |
---|
| 110 | |
---|
| 111 | $query = ' |
---|
| 112 | SELECT |
---|
| 113 | '.$conf['user_fields']['id'].' AS id, |
---|
| 114 | '.$conf['user_fields']['username'].' AS username |
---|
| 115 | FROM '.USERS_TABLE.' |
---|
| 116 | ;'; |
---|
| 117 | $result = pwg_query($query); |
---|
| 118 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 119 | { |
---|
| 120 | $id_of_user[ $row['username'] ] = $row['id']; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | $inserts = array(); |
---|
| 124 | |
---|
| 125 | foreach ($user_upload_conf['waiting_rows'] as $pending) |
---|
| 126 | { |
---|
| 127 | $source_path = get_complete_dir($pending['storage_category_id']).$pending['file']; |
---|
| 128 | |
---|
| 129 | if (is_file($source_path)) |
---|
| 130 | { |
---|
| 131 | $image_id = add_uploaded_file($source_path, $pending['file'], array($pending['storage_category_id']), 16); |
---|
| 132 | |
---|
| 133 | array_push( |
---|
| 134 | $inserts, |
---|
| 135 | array( |
---|
| 136 | 'image_id' => $image_id, |
---|
| 137 | 'added_on' => date ('Y-m-d H:i:s', $pending['date']), |
---|
| 138 | 'state' => 'moderation_pending', |
---|
| 139 | ) |
---|
| 140 | ); |
---|
| 141 | |
---|
| 142 | $data = array(); |
---|
| 143 | |
---|
| 144 | if (isset($pending['username']) and isset($id_of_user[ $pending['username'] ])) |
---|
| 145 | { |
---|
| 146 | $data['added_by'] = $id_of_user[ $pending['username'] ]; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | foreach (array('date_creation', 'author', 'name', 'comment') as $field) |
---|
| 150 | { |
---|
| 151 | $value = getAttribute($pending['infos'], $field); |
---|
| 152 | if (!empty($value)) |
---|
| 153 | { |
---|
| 154 | $data[$field] = pwg_db_real_escape_string($value); |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | if (count($data) > 0) |
---|
| 159 | { |
---|
| 160 | $data['id'] = $image_id; |
---|
| 161 | |
---|
| 162 | mass_updates( |
---|
| 163 | IMAGES_TABLE, |
---|
| 164 | array( |
---|
| 165 | 'primary' => array('id'), |
---|
| 166 | 'update' => array_keys($data) |
---|
| 167 | ), |
---|
| 168 | array($data) |
---|
| 169 | ); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | // deletion |
---|
| 173 | unlink($source_path); |
---|
| 174 | if (!isset($pending['tn_ext'])) |
---|
| 175 | { |
---|
| 176 | $pending['tn_ext'] = 'jpg'; |
---|
| 177 | } |
---|
| 178 | @unlink(get_thumbnail_path(array('path'=>$source_path, 'tn_ext'=>$pending['tn_ext']))); |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | if (count($inserts) > 0) |
---|
| 183 | { |
---|
| 184 | mass_inserts( |
---|
| 185 | $prefixeTable.'community_pendings', |
---|
| 186 | array_keys($inserts[0]), |
---|
| 187 | $inserts |
---|
| 188 | ); |
---|
| 189 | } |
---|
| 190 | } |
---|
| 191 | unlink($from_piwigo21_file); |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | function community_get_data_from_community21() |
---|
| 196 | { |
---|
| 197 | global $prefixeTable; |
---|
| 198 | |
---|
| 199 | $old_community_table = $prefixeTable.'community'; |
---|
| 200 | $query = 'SHOW TABLES;'; |
---|
| 201 | $result = pwg_query($query); |
---|
| 202 | while ($row = pwg_db_fetch_row($result)) |
---|
| 203 | { |
---|
| 204 | if ($old_community_table == $row[0]) |
---|
| 205 | { |
---|
| 206 | $inserts = array(); |
---|
| 207 | |
---|
| 208 | $query = ' |
---|
| 209 | SELECT |
---|
| 210 | * |
---|
| 211 | FROM '.$old_community_table.' |
---|
| 212 | ;'; |
---|
| 213 | $result = pwg_query($query); |
---|
| 214 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 215 | { |
---|
| 216 | array_push( |
---|
| 217 | $inserts, |
---|
| 218 | array( |
---|
| 219 | 'type' => 'user', |
---|
| 220 | 'user_id' => $row['user_id'], |
---|
| 221 | 'category_id' => null, |
---|
| 222 | 'recursive' => 'true', |
---|
| 223 | 'create_subcategories' => $row['permission_level'] == 2 ? 'true' : 'false', |
---|
| 224 | 'moderated' => 'false', |
---|
| 225 | ) |
---|
| 226 | ); |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | if (count($inserts) > 0) |
---|
| 230 | { |
---|
| 231 | mass_inserts( |
---|
| 232 | $prefixeTable.'community_permissions', |
---|
| 233 | array_keys($inserts[0]), |
---|
| 234 | $inserts |
---|
| 235 | ); |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | $query = 'DROP TABLE '.$old_community_table.';'; |
---|
| 239 | pwg_query($query); |
---|
| 240 | |
---|
| 241 | break; |
---|
| 242 | } |
---|
| 243 | } |
---|
| 244 | } |
---|
[9566] | 245 | |
---|
| 246 | function community_create_default_permission() |
---|
| 247 | { |
---|
| 248 | global $prefixeTable; |
---|
| 249 | |
---|
[23085] | 250 | // is there a "Community" album? |
---|
| 251 | $query = ' |
---|
| 252 | SELECT |
---|
| 253 | id |
---|
| 254 | FROM '.CATEGORIES_TABLE.' |
---|
| 255 | WHERE name = \'Community\' |
---|
| 256 | ;'; |
---|
| 257 | $result = pwg_query($query); |
---|
| 258 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 259 | { |
---|
| 260 | $category_id = $row['id']; |
---|
| 261 | break; |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | if (!isset($category_id)) |
---|
| 265 | { |
---|
| 266 | // create an album "Community" |
---|
| 267 | $category_info = create_virtual_category('Community'); |
---|
| 268 | $category_id = $category_info['id']; |
---|
| 269 | } |
---|
| 270 | |
---|
[9566] | 271 | $insert = array( |
---|
| 272 | 'type' => 'any_registered_user', |
---|
[23085] | 273 | 'category_id' => $category_id, |
---|
[9566] | 274 | 'recursive' => 'true', |
---|
| 275 | 'create_subcategories' => 'true', |
---|
| 276 | 'moderated' => 'true', |
---|
| 277 | ); |
---|
| 278 | |
---|
| 279 | mass_inserts($prefixeTable.'community_permissions', array_keys($insert), array($insert)); |
---|
| 280 | } |
---|
[9441] | 281 | ?> |
---|