Verzeichnisstruktur phpBB-3.0.0


Veröffentlicht
12.12.2007

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

adjust_avatars.php

Zuletzt modifiziert: 09.10.2024, 12:50 - Dateigröße: 3.49 KiB


 001  <?php
 002  /**
 003  * Corrects avatar filenames to match the new avatar delivery method.
 004  *
 005  * You should make a backup from your users table and the avatar directory in case something goes wrong
 006  */
 007  die("Please read the first lines of this script for instructions on how to enable it");
 008   
 009  set_time_limit(0);
 010   
 011  define('IN_PHPBB', true);
 012  $phpbb_root_path = './../';
 013  $phpEx = substr(strrchr(__FILE__, '.'), 1);
 014  include($phpbb_root_path . 'common.'.$phpEx);
 015   
 016  // Start session management
 017  $user->session_begin();
 018  $auth->acl($user->data);
 019  $user->setup();
 020   
 021  $echos = 0;
 022   
 023  if (!isset($config['avatar_salt']))
 024  {
 025      $cache->purge();
 026      if (!isset($config['avatar_salt']))
 027      {
 028          die('database not up to date');
 029      }
 030      die('database not up to date');
 031  }
 032   
 033  // let's start with the users using a group_avatar.
 034  $sql = 'SELECT group_id, group_avatar
 035      FROM ' . GROUPS_TABLE . '
 036      WHERE group_avatar_type = ' . AVATAR_UPLOAD;
 037   
 038  // We'll skip these, so remember them
 039  $group_avatars = array();
 040   
 041  echo '<br /> Updating groups' . "\n";
 042   
 043  $result = $db->sql_query($sql);
 044   
 045  while ($row = $db->sql_fetchrow($result))
 046  {
 047      $new_avatar_name = adjust_avatar($row['group_avatar'], 'g' . $row['group_id']);
 048      $group_avatars[] = $new_avatar_name;
 049      
 050      // failure is probably due to the avatar name already being adjusted
 051      if ($new_avatar_name !== false)
 052      {
 053          $sql = 'UPDATE ' . USERS_TABLE . "
 054              SET user_avatar = '" . $db->sql_escape($new_avatar_name) . "'
 055              WHERE user_avatar = '" . $db->sql_escape($row['group_avatar']) . "' 
 056              AND user_avatar_type = " . AVATAR_UPLOAD;
 057          $db->sql_query($sql);
 058          
 059          $sql = 'UPDATE ' . GROUPS_TABLE . "
 060              SET group_avatar = '" . $db->sql_escape($new_avatar_name) . "'
 061              WHERE group_id = {$row['group_id']}";
 062          $db->sql_query($sql);
 063      }
 064      else
 065      {
 066          echo '<br /> Failed updating group ' . $row['group_id'] . "\n";
 067      }
 068   
 069      if ($echos > 200)
 070      {
 071          echo '<br />' . "\n";
 072          $echos = 0;
 073      }
 074   
 075      echo '.';
 076      $echos++;
 077   
 078      flush();
 079  }
 080  $db->sql_freeresult($result);
 081   
 082  $sql = 'SELECT user_id, username, user_avatar, user_avatar_type
 083      FROM ' . USERS_TABLE . ' 
 084      WHERE user_avatar_type = ' . AVATAR_UPLOAD . ' 
 085      AND ' . $db->sql_in_set('user_avatar', $group_avatars, true, true);
 086  $result = $db->sql_query($sql);
 087   
 088  echo '<br /> Updating users' . "\n";
 089   
 090  while ($row = $db->sql_fetchrow($result))
 091  {
 092      $new_avatar_name = adjust_avatar($row['user_avatar'], $row['user_id']);
 093   
 094      // failure is probably due to the avatar name already being adjusted
 095      if ($new_avatar_name !== false)
 096      {
 097          $sql = 'UPDATE ' . USERS_TABLE . "
 098              SET user_avatar = '" . $db->sql_escape($new_avatar_name) . "'
 099              WHERE user_id = {$row['user_id']}";
 100          $db->sql_query($sql);
 101      }
 102      else
 103      {
 104          // nuke this avatar
 105          $sql = 'UPDATE ' . USERS_TABLE . "
 106              SET user_avatar = '', user_avatar_type = 0
 107              WHERE user_id = {$row['user_id']}";
 108          $db->sql_query($sql);
 109          echo '<br /> Failed updating user ' . $row['user_id'] . "\n";
 110      }
 111      
 112      if ($echos > 200)
 113      {
 114          echo '<br />' . "\n";
 115          $echos = 0;
 116      }
 117   
 118      echo '.';
 119      $echos++;
 120   
 121      flush();
 122  }
 123   
 124  $db->sql_freeresult($result);
 125   
 126  echo 'FINISHED';
 127   
 128  // Done
 129  $db->sql_close();
 130   
 131  function adjust_avatar($old_name, $midfix)
 132  {
 133      global $config, $phpbb_root_path;
 134      
 135      $avatar_path = $phpbb_root_path . $config['avatar_path'];
 136      $extension = strtolower(substr(strrchr($old_name, '.'), 1));
 137      $new_name = $config['avatar_salt'] . '_' . $midfix . '.' . $extension;
 138   
 139      if (@file_exists($avatar_path . '/' . $old_name) && @is_writable($avatar_path . '/' . $old_name) && @is_writable($avatar_path . '/' . $new_name))
 140      {
 141          @rename($avatar_path . '/' . $old_name, $avatar_path . '/' . $new_name);
 142          return $midfix . '.' . $extension;
 143      }
 144      return false;
 145  }
 146   
 147  ?>