Subversion Repositories Applications.papyrus

Rev

Rev 831 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
831 florian 1
<?php
2
if(!defined("PHORUM5_CONVERSION")) return;
3
 
4
// Phorum3 - to - Phorum5 Conversion Library
5
 
6
function phorum_convert_check_groups($link) {
7
    GLOBAL $CONVERT;
8
 
9
    $sql="show tables LIKE '{$CONVERT['forumstable']}_groups'";
10
    $res=mysql_query($sql,$link);
11
    if(mysql_num_rows($res)>0) {
12
        $ret=true;
13
    } else {
14
        $ret=false;
15
    }
16
    return $ret;
17
}
18
 
19
 
20
function phorum_convert_check_users($link) {
21
    GLOBAL $CONVERT;
22
 
23
    $sql="show tables LIKE '{$CONVERT['forumstable']}_auth'";
24
    $res=mysql_query($sql,$link);
25
    if(mysql_num_rows($res)>0) {
26
        $ret=true;
27
    } else {
28
        $ret=false;
29
    }
30
    return $ret;
31
}
32
 
33
function phorum_convert_getForums($link) {
34
	global $CONVERT;
35
 
36
    $sql="SELECT * FROM {$CONVERT['forumstable']} ORDER BY id ASC";
37
    $res=mysql_unbuffered_query($sql,$link);
38
    $forums=array();
39
 
40
    if ($err = mysql_error($link)) phorum_db_mysql_error("$err: $sql");
41
 
42
 
43
    echo "Reading forums from phorum3-table {$CONVERT['forumstable']} ...{$CONVERT['lbr']}";
44
    while($row=mysql_fetch_array($res)) {
45
       $forums[$row['id']]=$row;
46
    }
47
 
48
	return $forums;
49
}
50
 
51
 
52
function phorum_convert_getGroups($link) {
53
	global $CONVERT;
54
 
55
    $sql="SELECT * FROM {$CONVERT['forumstable']}_groups ORDER BY id ASC";
56
    $res=mysql_unbuffered_query($sql,$link);
57
    $groups=array();
58
 
59
    if ($err = mysql_error($link)) phorum_db_mysql_error("$err: $sql");
60
 
61
    while($row=mysql_fetch_array($res)) {
62
       $groups[$row['id']]=$row;
63
       $groups[$row['id']]['open']=PHORUM_GROUP_CLOSED;
64
 
65
    }
66
 
67
	return $groups;
68
}
69
 
70
function phorum_convert_getForumGroups($forum_id) {
71
    global $CONVERT;
72
 
73
    $sql="SELECT * FROM {$CONVERT['forumstable']}_forum2group";
74
    $res=mysql_unbuffered_query($sql,$GLOBALS['oldlink']);
75
    $groups=array();
76
    while($row=mysql_fetch_array($res)) {
77
        $groups[]=$row['group_id'];
78
    }
79
 
80
    return $groups;
81
}
82
 
83
function phorum_convert_prepareForum($forumdata) {
84
     global $CONVERT;
85
 
86
     if($forumdata['folder']) { // folders
87
         if(!get_magic_quotes_runtime()){
88
               $forumdata['name'] = $forumdata['name'];
89
               $forumdata['description'] = $forumdata['description'];
90
         }
91
 
92
         $newforum = array(
93
            		 'forum_id' => $forumdata['id'],
94
            		 'name' => $forumdata['name'],
95
            		 'active' => $forumdata['active'],
96
            		 'description' => $forumdata['description'],
97
            		 'template' => 'default',
98
            		 'folder_flag' => $forumdata['folder'],
99
            		 'parent_id' => $forumdata['parent'],
100
                     'pub_perms' => PHORUM_USER_ALLOW_READ,
101
                     'reg_perms' => PHORUM_USER_ALLOW_READ
102
                     );
103
 
104
 
105
     } else { // forums
106
         echo "Preparing data for forum {$forumdata['name']} ...{$CONVERT['lbr']}";
107
         // rewriting some vars
108
         if($forumdata['moderation'] == "a")
109
            $moderation = PHORUM_MODERATE_ON;
110
         else
111
            $moderation = PHORUM_MODERATE_OFF;
112
 
113
         if($forumdata['moderation'] == "n")
114
             $email_mod = PHORUM_EMAIL_MODERATOR_OFF;
115
         else
116
             $email_mod = PHORUM_EMAIL_MODERATOR_ON;
117
 
118
         if($forumdata['collapse'] == 1)
119
            $threaded = 0;
120
         else
121
            $threaded = 1;
122
 
123
         if($forumdata['multi_level'] == 2)
124
            $float_to_top = 1;
125
         else
126
            $float_to_top = 0;
127
 
128
         if(!isset($forumdata['allow_edit'])) // hmm could this really happen?
129
             $forumdata['allow_edit'] = 0;
130
 
131
 
132
         if(!get_magic_quotes_runtime()){
133
               $forumdata['name'] = $forumdata['name'];
134
               $forumdata['description'] = $forumdata['description'];
135
         }
136
 
137
         // checking security setting
138
         if($forumdata['security'] > 1) {
139
             if($forumdata['security'] == 2) { // login to post
140
                 $pub_perms= 0 | PHORUM_USER_ALLOW_READ;
141
                 $reg_perms= 0 | PHORUM_USER_ALLOW_READ | PHORUM_USER_ALLOW_NEW_TOPIC | PHORUM_USER_ALLOW_REPLY | PHORUM_USER_ALLOW_EDIT;
142
 
143
             } elseif($forumdata['security'] == 3) { // login to read (so to say, login to everything)
144
                 $pub_perms= 0;
145
                 $reg_perms= 0 | PHORUM_USER_ALLOW_READ | PHORUM_USER_ALLOW_NEW_TOPIC | PHORUM_USER_ALLOW_REPLY | PHORUM_USER_ALLOW_EDIT;
146
             }
147
         } else {
148
             $pub_perms = 0 | PHORUM_USER_ALLOW_READ | PHORUM_USER_ALLOW_NEW_TOPIC | PHORUM_USER_ALLOW_REPLY;
149
             $reg_perms = 0 | PHORUM_USER_ALLOW_READ | PHORUM_USER_ALLOW_NEW_TOPIC | PHORUM_USER_ALLOW_REPLY | PHORUM_USER_ALLOW_EDIT;
150
         }
151
 
152
         // checking groups
153
         if($CONVERT['do_groups']) {
154
             $groups=phorum_convert_getForumGroups($forumdata['id']);
155
             if(count($groups) && ($forumdata['permissions'] == 1 || $forumdata['permissions'] > 2) ) {
156
                 foreach($groups as $bogus => $group_id) {
157
                     $CONVERT['groups'][$group_id]['permissions'][$forumdata['id']]=$reg_perms;
158
                 }
159
                 $reg_perms=0;
160
                 $pub_perms=0;
161
             }
162
         }
163
 
164
 
165
         $newforum = array(
166
            		 'forum_id' => $forumdata['id'],
167
            		 'name' => $forumdata['name'],
168
            		 'active' => $forumdata['active'],
169
            		 'description' => $forumdata['description'],
170
            		 'template' => 'default',
171
            		 'folder_flag' => $forumdata['folder'],
172
            		 'parent_id' => $forumdata['parent'],
173
                     'list_length_flat' => $forumdata['display'],
174
                     'list_length_threaded' => $forumdata['display'],
175
                     'read_length' => 20,
176
                     'moderation' => $moderation,
177
                     'threaded_list' => $threaded,
178
                     'threaded_read' => $threaded,
179
                     'float_to_top' => $float_to_top,
180
                     'allow_attachment_types' => $forumdata['upload_types'],
181
                     'max_attachment_size' => $forumdata['upload_size'],
182
                     'max_attachments' => $forumdata['max_uploads'],
183
                     'pub_perms' => $pub_perms,
184
                     'reg_perms' => $reg_perms,
185
                     'display_ip_address' => $forumdata['showip'],
186
                     'allow_email_notify' => $forumdata['emailnotification'],
187
                     'language' => basename($forumdata['lang'],".php"),
188
                     'email_moderators' => $email_mod,
189
                     'edit_post' => $forumdata['allow_edit']
190
                     );
191
    }
192
    return $newforum;
193
}
194
 
195
function phorum_convert_getAttachments($table_name) {
196
    GLOBAL $CONVERT;
197
 
198
    $sql="SELECT * FROM ".$table_name."_attachments";
199
    $res=mysql_unbuffered_query($sql,$GLOBALS['oldlink']);
200
    $att=array();
201
    while($row=mysql_fetch_assoc($res)) {
202
        $att[$row['message_id']][]=$row;
203
    }
204
 
205
    return $att;
206
}
207
 
208
function phorum_convert_selectMessages($forumdata,$link) {
209
 
210
    $sql="SELECT a.*,b.body,UNIX_TIMESTAMP(a.datestamp) as unixtime  FROM ".$forumdata['table_name']." as a, ".$forumdata['table_name']."_bodies as b WHERE b.id = a.id ORDER BY a.id ASC";
211
    $res=mysql_unbuffered_query($sql, $link);
212
 
213
    if ($err = mysql_error($link)) phorum_db_mysql_error("$err: $sql");
214
 
215
    return $res;
216
}
217
 
218
function phorum_convert_getNextMessage($res,$table_name) {
219
      global $CONVERT;
220
 
221
      // fetching the message from the database
222
      $mdata = mysql_fetch_assoc($res);
223
      if(!$mdata) {
224
            return false;
225
      }
226
      $max_id= $CONVERT['max_id'];
227
 
228
      $id=$mdata['id'];
229
      if($mdata['closed'])
230
            $closed=1;
231
      else
232
            $closed=0;
233
 
234
      if($mdata['approved'] != "Y")
235
            $post_status=PHORUM_STATUS_HOLD;
236
      else
237
            $post_status=PHORUM_STATUS_APPROVED;
238
 
239
      $post_sort=PHORUM_SORT_DEFAULT;
240
 
241
      $parentid=($mdata['parent']>0)?($mdata['parent']+$max_id):0;
242
 
243
      if(!get_magic_quotes_runtime()){
244
            $mdata['author'] = $mdata['author'];
245
            $mdata['subject'] = $mdata['subject'];
246
            $mdata['body'] = $mdata['body'];
247
            $mdata['email'] = $mdata['email'];
248
      }
249
 
250
      //find [%sig%] and cut it
251
      if (preg_match ("/\[%sig%\]/", $mdata['body'])) {
252
      	$mdata['body'] = preg_replace ( "/\[%sig%\]/", "", $mdata['body']);
253
      	$add_signature = true;
254
      } else {
255
        $add_signature = false;
256
      }
257
 
258
      // bah, there are really people trying to upgrade from 3.2.x ;)
259
      $userid = (isset($mdata['userid']) ? $mdata['userid'] : 0);
260
 
261
 
262
      // building the new message
263
      $newmessage = array(
264
          'message_id'=> $mdata['id']+$max_id,
265
          'forum_id'  => $CONVERT['forum_id'],
266
          'datestamp' => $mdata['unixtime'],
267
          'thread'    => ($mdata['thread']+$max_id),
268
          'parent_id' => $parentid,
269
          'author'    => $mdata['author'],
270
          'subject'   => $mdata['subject'],
271
          'email'     => $mdata['email'],
272
          'ip'        => $mdata['host'],
273
          'user_id'   => $userid,
274
          'moderator_post' => 0,
275
          'status'    => $post_status,
276
          'sort'      => $post_sort,
277
          'msgid'     => $mdata['msgid'],
278
          'closed'    => $closed,
279
          'body'      => $mdata['body']
280
      );
281
 
282
      if($add_signature) {
283
          $newmessage["meta"]["show_signature"]=1;
284
      }
285
      if(isset($mdata['viewcount'])) {
286
          $newmessage['viewcount']=$mdata['viewcount'];
287
      }
288
      $newmessage['viewcount'] = (isset($mdata['viewcount']) ? $mdata['viewcount'] : 0);
289
      // converting attachments if needed
290
      $inserted_files=array();
291
      if (isset($CONVERT['attachments'][$mdata['id']]) && count($CONVERT['attachments'][$mdata['id']])) {
292
          foreach($CONVERT['attachments'][$mdata['id']] as $attachment) {
293
              $filename = $CONVERT['attachmentdir']."/".$table_name."/".$attachment['id'].strtolower(strrchr($attachment['filename'], "."));
294
              if(file_exists($filename) && filesize($filename)>0) {
295
                  $fp=fopen($filename, "r");
296
                  $buffer=base64_encode(fread($fp, filesize($filename)));
297
                  fclose($fp);
298
                  $file_id = phorum_db_file_save($userid, $attachment['filename'], filesize($filename), $buffer, $newmessage['message_id']);
299
                  unset($buffer); // free that large buffer
300
                  $inserted_files[]=array("file_id"=>$file_id, "name"=>$attachment['filename'], "size"=>filesize($filename));
301
              }
302
          }
303
      }
304
      if(count($inserted_files)) {
305
          $newmessage["meta"]["attachments"]=$inserted_files;
306
      }
307
 
308
 
309
      return $newmessage;
310
}
311
 
312
function phorum_convert_selectUsers($link) {
313
    global $CONVERT;
314
 
315
 
316
    // collecting permissions
317
    $CONVERT['perms'] = phorum_convert_getPermissions($link);
318
 
319
    // selecting the users
320
    $res=mysql_unbuffered_query("SELECT * FROM ".$CONVERT['forumstable']."_auth ORDER BY id", $link);
321
 
322
    if(mysql_error($link)) {
323
        return false;
324
    }
325
 
326
    return $res;
327
}
328
 
329
function phorum_convert_getNextUser($res) {
330
    global $CONVERT;
331
 
332
    $userdata=array();
333
    $userdata=mysql_fetch_assoc($res);
334
    if(!$userdata) {
335
        return false;
336
    }
337
 
338
    unset($userdata['lang']);
339
    unset($userdata['password_tmp']);
340
    unset($userdata['combined_token']);
341
    unset($userdata['max_group_permission_level']);
342
    unset($userdata['permission_level']);
343
 
344
    $userdata['user_id']=$userdata['id'];
345
    unset($userdata['id']);
346
 
347
    $userdata['real_name']=$userdata['name'];
348
    unset($userdata['name']);
349
 
350
    $userdata['active']=1;
351
    if(isset($CONVERT['perms'][$userdata['user_id']][0])) {
352
        echo "Setting {$userdata['user_id']} as administrator.{$CONVERT['lbr']}";
353
        $userdata['admin']=1;
354
        unset($CONVERT['perms'][$userdata['user_id']][0]);
355
    }
356
    if(isset($CONVERT['perms'][$userdata['user_id']])) {
357
        foreach($CONVERT['perms'][$userdata['user_id']] as $key => $val) {
358
            echo "Setting {$userdata['user_id']} as moderator for forum $key.{$CONVERT['lbr']}";
359
            $userdata['forum_permissions'][$key] = 0 | PHORUM_USER_ALLOW_READ | PHORUM_USER_ALLOW_NEW_TOPIC | PHORUM_USER_ALLOW_REPLY | PHORUM_USER_ALLOW_EDIT | PHORUM_USER_ALLOW_MODERATE_MESSAGES;
360
        }
361
    }
362
    // set the date_added and active to current time
363
    $userdata["date_added"]=time();
364
    $userdata["date_last_active"]=time();
365
 
366
    return $userdata;
367
 
368
}
369
 
370
function phorum_convert_getUserGroups($link) {
371
    GLOBAL $CONVERT;
372
 
373
    $res=mysql_unbuffered_query("SELECT * FROM ".$CONVERT['forumstable']."_user2group",$link);
374
 
375
    if(mysql_error()) {
376
       echo "No user2group-table found? : ".mysql_error().$CONVERT['lbr'];
377
       return false;
378
    }
379
    $groups=array();
380
 
381
    while($row=mysql_fetch_array($res)) {
382
         $groups[$row['user_id']][$row['group_id']]=PHORUM_USER_GROUP_APPROVED;
383
    }
384
 
385
    return $groups;
386
}
387
 
388
function phorum_convert_getPermissions($link) {
389
    GLOBAL $CONVERT;
390
 
391
    $res=mysql_unbuffered_query("SELECT * FROM ".$CONVERT['forumstable']."_moderators",$link);
392
 
393
    if(mysql_error()) {
394
       echo "No moderators-table found? : ".mysql_error().$CONVERT['lbr'];
395
       return false;
396
    }
397
 
398
    while($row=mysql_fetch_array($res)) {
399
         $perms[$row['user_id']][$row['forum_id']]=true;
400
    }
401
    return $perms;
402
}
403
 
404
?>