Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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

style_update.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 3.32 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb\db\migration\data\v31x;
 015   
 016  class style_update extends \phpbb\db\migration\migration
 017  {
 018      static public function depends_on()
 019      {
 020          return array('\phpbb\db\migration\data\v310\gold');
 021      }
 022   
 023      public function update_data()
 024      {
 025          return array(
 026              array('custom', array(array($this, 'update_installed_styles'))),
 027          );
 028      }
 029   
 030      public function update_installed_styles()
 031      {
 032          // Get all currently available styles
 033          $styles = $this->find_style_dirs();
 034          $style_paths = $style_ids = array();
 035   
 036          $sql = 'SELECT style_path, style_id
 037                  FROM ' . $this->table_prefix . 'styles';
 038          $result = $this->db->sql_query($sql);
 039          while ($styles_row = $this->db->sql_fetchrow())
 040          {
 041              if (in_array($styles_row['style_path'], $styles))
 042              {
 043                  $style_paths[] = $styles_row['style_path'];
 044                  $style_ids[] = $styles_row['style_id'];
 045              }
 046          }
 047          $this->db->sql_freeresult($result);
 048   
 049          // Install prosilver if no style is available and prosilver can be installed
 050          if (empty($style_paths) && in_array('prosilver', $styles))
 051          {
 052              // Try to parse config file
 053              $cfg = parse_cfg_file($this->phpbb_root_path . 'styles/prosilver/style.cfg');
 054   
 055              // Stop running this if prosilver cfg file can't be read
 056              if (empty($cfg))
 057              {
 058                  throw new \RuntimeException('No styles available and could not fall back to prosilver.');
 059              }
 060   
 061              $style = array(
 062                  'style_name'        => 'prosilver',
 063                  'style_copyright'    => '&copy; phpBB Limited',
 064                  'style_active'        => 1,
 065                  'style_path'        => 'prosilver',
 066                  'bbcode_bitfield'    => 'kNg=',
 067                  'style_parent_id'    => 0,
 068                  'style_parent_tree'    => '',
 069              );
 070   
 071              // Add to database
 072              $this->db->sql_transaction('begin');
 073   
 074              $sql = 'INSERT INTO ' . $this->table_prefix . 'styles
 075                      ' . $this->db->sql_build_array('INSERT', $style);
 076              $this->db->sql_query($sql);
 077   
 078              $style_id = $this->db->sql_nextid();
 079              $style_ids[] = $style_id;
 080   
 081              $this->db->sql_transaction('commit');
 082   
 083              // Set prosilver to default style
 084              $this->config->set('default_style', $style_id);
 085          }
 086          else if (empty($styles) && empty($available_styles))
 087          {
 088              throw new \RuntimeException('No valid styles available');
 089          }
 090   
 091          // Make sure default style is available
 092          if (!in_array($this->config['default_style'], $style_ids))
 093          {
 094              $this->config->set('default_style', array_pop($style_ids));
 095          }
 096   
 097          // Reset users to default style if their user_style is nonexistent
 098          $sql = 'UPDATE ' . $this->table_prefix . "users
 099              SET user_style = {$this->config['default_style']}
 100              WHERE " . $this->db->sql_in_set('user_style', $style_ids, true, true);
 101          $this->db->sql_query($sql);
 102      }
 103   
 104      /**
 105       * Find all directories that have styles
 106       * Copied from acp_styles
 107       *
 108       * @return array Directory names
 109       */
 110      protected function find_style_dirs()
 111      {
 112          $styles = array();
 113          $styles_path = $this->phpbb_root_path . 'styles/';
 114   
 115          $dp = @opendir($styles_path);
 116          if ($dp)
 117          {
 118              while (($file = readdir($dp)) !== false)
 119              {
 120                  $dir = $styles_path . $file;
 121                  if ($file[0] == '.' || !is_dir($dir))
 122                  {
 123                      continue;
 124                  }
 125   
 126                  if (file_exists("{$dir}/style.cfg"))
 127                  {
 128                      $styles[] = $file;
 129                  }
 130              }
 131              closedir($dp);
 132          }
 133   
 134          return $styles;
 135      }
 136  }
 137