Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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

acp_icons.php

Zuletzt modifiziert: 01.05.2026, 11:25 - Dateigröße: 29.67 KiB


 0001  <?php
 0002  /**
 0003  *
 0004  * This file is part of the phpBB Forum Software package.
 0005  *
 0006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 0007  * @license GNU General Public License, version 2 (GPL-2.0)
 0008  *
 0009  * For full copyright and license information, please see
 0010  * the docs/CREDITS.txt file.
 0011  *
 0012  */
 0013   
 0014  /**
 0015  * @ignore
 0016  */
 0017  if (!defined('IN_PHPBB'))
 0018  {
 0019      exit;
 0020  }
 0021   
 0022  /**
 0023    * @todo {smilies} check regular expressions for special char replacements (stored specialchared in db)
 0024    */
 0025  class acp_icons
 0026  {
 0027      var $u_action;
 0028   
 0029      function main($id, $mode)
 0030      {
 0031          global $db, $user, $template, $cache;
 0032          global $config, $phpbb_root_path;
 0033          global $request, $phpbb_container;
 0034   
 0035          $user->add_lang('acp/posting');
 0036   
 0037          // Set up general vars
 0038          $action = $request->variable('action', '');
 0039          $action = (isset($_POST['add'])) ? 'add' : $action;
 0040          $action = (isset($_POST['edit'])) ? 'edit' : $action;
 0041          $action = (isset($_POST['import'])) ? 'import' : $action;
 0042          $icon_id = $request->variable('id', 0);
 0043          $submit = $request->is_set_post('submit', false);
 0044   
 0045          $form_key = 'acp_icons';
 0046          add_form_key($form_key);
 0047   
 0048          $mode = ($mode == 'smilies') ? 'smilies' : 'icons';
 0049   
 0050          $this->tpl_name = 'acp_icons';
 0051   
 0052          // What are we working on?
 0053          switch ($mode)
 0054          {
 0055              case 'smilies':
 0056                  $table = SMILIES_TABLE;
 0057                  $lang = 'SMILIES';
 0058                  $fields = 'smiley';
 0059                  $img_path = $config['smilies_path'];
 0060              break;
 0061   
 0062              case 'icons':
 0063                  $table = ICONS_TABLE;
 0064                  $lang = 'ICONS';
 0065                  $fields = 'icons';
 0066                  $img_path = $config['icons_path'];
 0067              break;
 0068          }
 0069   
 0070          $this->page_title = 'ACP_' . $lang;
 0071   
 0072          // Clear some arrays
 0073          $_images = $_paks = array();
 0074          $notice = '';
 0075   
 0076          // Grab file list of paks and images
 0077          if ($action == 'edit' || $action == 'add' || $action == 'import')
 0078          {
 0079              $imglist = filelist($phpbb_root_path . $img_path, '');
 0080   
 0081              foreach ($imglist as $path => $img_ary)
 0082              {
 0083                  if (empty($img_ary))
 0084                  {
 0085                      continue;
 0086                  }
 0087   
 0088                  asort($img_ary, SORT_STRING);
 0089   
 0090                  foreach ($img_ary as $img)
 0091                  {
 0092                      $img_size = getimagesize($phpbb_root_path . $img_path . '/' . $path . $img);
 0093   
 0094                      if ($img_size)
 0095                      {
 0096                          if (!$img_size[0] || !$img_size[1] || strlen($img) > 255)
 0097                          {
 0098                              continue;
 0099                          }
 0100   
 0101                          // adjust the width and height to be lower than 128px while perserving the aspect ratio (for icons)
 0102                          if ($mode == 'icons')
 0103                          {
 0104                              if ($img_size[0] > 127 && $img_size[0] > $img_size[1])
 0105                              {
 0106                                  $img_size[1] = (int) ($img_size[1] * (127 / $img_size[0]));
 0107                                  $img_size[0] = 127;
 0108                              }
 0109                              else if ($img_size[1] > 127)
 0110                              {
 0111                                  $img_size[0] = (int) ($img_size[0] * (127 / $img_size[1]));
 0112                                  $img_size[1] = 127;
 0113                              }
 0114                          }
 0115                      }
 0116                      else
 0117                      {
 0118                          // getimagesize can't read the dimensions of the SVG files
 0119                          // https://bugs.php.net/bug.php?id=71517
 0120                          $xml_get = simplexml_load_file($phpbb_root_path . $img_path . '/' . $path . $img);
 0121   
 0122                          $svg_width = intval($xml_get['width']);
 0123                          $svg_height = intval($xml_get['height']);
 0124                      }
 0125   
 0126                      $_images[$path . $img]['file'] = $path . $img;
 0127   
 0128                      // Give SVG a fallback on failure
 0129                      $_images[$path . $img]['width'] = $img_size ? $img_size[0] : ($svg_width ?: 32);
 0130                      $_images[$path . $img]['height'] = $img_size ? $img_size[1] : ($svg_height ?: 32);
 0131                  }
 0132              }
 0133              unset($imglist);
 0134   
 0135              if ($dir = @opendir($phpbb_root_path . $img_path))
 0136              {
 0137                  while (($file = readdir($dir)) !== false)
 0138                  {
 0139                      if (is_file($phpbb_root_path . $img_path . '/' . $file) && preg_match('#\.pak$#i', $file))
 0140                      {
 0141                          $_paks[] = $file;
 0142                      }
 0143                  }
 0144                  closedir($dir);
 0145   
 0146                  if (!empty($_paks))
 0147                  {
 0148                      asort($_paks, SORT_STRING);
 0149                  }
 0150              }
 0151          }
 0152   
 0153          // What shall we do today? Oops, I believe that's trademarked ...
 0154          switch ($action)
 0155          {
 0156              case 'edit':
 0157                  unset($_images);
 0158                  $_images = array();
 0159   
 0160              // no break;
 0161   
 0162              case 'add':
 0163   
 0164                  $smilies = $default_row = array();
 0165                  $smiley_options = $order_list = $add_order_list = '';
 0166   
 0167                  if ($action == 'add' && $mode == 'smilies')
 0168                  {
 0169                      $sql = 'SELECT *
 0170                          FROM ' . SMILIES_TABLE . '
 0171                          ORDER BY smiley_order';
 0172                      $result = $db->sql_query($sql);
 0173   
 0174                      while ($row = $db->sql_fetchrow($result))
 0175                      {
 0176                          if (empty($smilies[$row['smiley_url']]))
 0177                          {
 0178                              $smilies[$row['smiley_url']] = $row;
 0179                          }
 0180                      }
 0181                      $db->sql_freeresult($result);
 0182   
 0183                      if (count($smilies))
 0184                      {
 0185                          foreach ($smilies as $row)
 0186                          {
 0187                              $selected = false;
 0188   
 0189                              if (!$smiley_options)
 0190                              {
 0191                                  $selected = true;
 0192                                  $default_row = $row;
 0193                              }
 0194                              $smiley_options .= '<option value="' . $row['smiley_url'] . '"' . (($selected) ? ' selected="selected"' : '') . '>' . $row['smiley_url'] . '</option>';
 0195   
 0196                              $template->assign_block_vars('smile', array(
 0197                                  'SMILEY_URL'    => addslashes($row['smiley_url']),
 0198                                  'CODE'            => addslashes($row['code']),
 0199                                  'EMOTION'        => addslashes($row['emotion']),
 0200                                  'WIDTH'            => $row['smiley_width'],
 0201                                  'HEIGHT'        => $row['smiley_height'],
 0202                                  'ORDER'            => $row['smiley_order'] + 1,
 0203                              ));
 0204                          }
 0205                      }
 0206                  }
 0207   
 0208                  $sql = "SELECT *
 0209                      FROM $table
 0210                      ORDER BY {$fields}_order " . (($icon_id || $action == 'add') ? 'DESC' : 'ASC');
 0211                  $result = $db->sql_query($sql);
 0212   
 0213                  $data = array();
 0214                  $after = false;
 0215                  $order_lists = array('', '');
 0216                  $add_order_lists = array('', '');
 0217                  $display_count = 0;
 0218   
 0219                  while ($row = $db->sql_fetchrow($result))
 0220                  {
 0221                      if ($action == 'add')
 0222                      {
 0223                          unset($_images[$row[$fields . '_url']]);
 0224                      }
 0225   
 0226                      if ($row[$fields . '_id'] == $icon_id)
 0227                      {
 0228                          $after = true;
 0229                          $data[$row[$fields . '_url']] = $row;
 0230                      }
 0231                      else
 0232                      {
 0233                          if ($action == 'edit' && !$icon_id)
 0234                          {
 0235                              $data[$row[$fields . '_url']] = $row;
 0236                          }
 0237   
 0238                          $selected = '';
 0239                          if (!empty($after))
 0240                          {
 0241                              $selected = ' selected="selected"';
 0242                              $after = false;
 0243                          }
 0244                          if ($row['display_on_posting'])
 0245                          {
 0246                              $display_count++;
 0247                          }
 0248                          $after_txt = ($mode == 'smilies') ? $row['code'] : $row['icons_url'];
 0249                          $order_lists[$row['display_on_posting']] = '<option value="' . ($row[$fields . '_order'] + 1) . '"' . $selected . '>' . sprintf($user->lang['AFTER_' . $lang], ' -&gt; ' . $after_txt) . '</option>' . $order_lists[$row['display_on_posting']];
 0250   
 0251                          if (!empty($default_row))
 0252                          {
 0253                              $add_order_lists[$row['display_on_posting']] = '<option value="' . ($row[$fields . '_order'] + 1) . '"' . (($row[$fields . '_id'] == $default_row['smiley_id']) ? ' selected="selected"' : '') . '>' . sprintf($user->lang['AFTER_' . $lang], ' -&gt; ' . $after_txt) . '</option>' . $add_order_lists[$row['display_on_posting']];
 0254                          }
 0255                      }
 0256                  }
 0257                  $db->sql_freeresult($result);
 0258   
 0259                  $order_list = '<option value="1"' . ((!isset($after)) ? ' selected="selected"' : '') . '>' . $user->lang['FIRST'] . '</option>';
 0260                  $add_order_list = '<option value="1">' . $user->lang['FIRST'] . '</option>';
 0261   
 0262                  if ($action == 'add')
 0263                  {
 0264                      $data = $_images;
 0265                  }
 0266   
 0267                  $colspan = (($mode == 'smilies') ? 7 : 6);
 0268                  $colspan += ($icon_id) ? 1 : 0;
 0269                  $colspan += ($action == 'add') ? 2 : 0;
 0270   
 0271                  $template->assign_vars(array(
 0272                      'S_EDIT'        => true,
 0273                      'S_SMILIES'        => ($mode == 'smilies') ? true : false,
 0274                      'S_ADD'            => ($action == 'add') ? true : false,
 0275   
 0276                      'S_ORDER_LIST_DISPLAY'        => $order_list . $order_lists[1],
 0277                      'S_ORDER_LIST_UNDISPLAY'    => $order_list . $order_lists[0],
 0278                      'S_ORDER_LIST_DISPLAY_COUNT'    => $display_count + 1,
 0279   
 0280                      'L_TITLE'        => $user->lang['ACP_' . $lang],
 0281                      'L_EXPLAIN'        => $user->lang['ACP_' . $lang . '_EXPLAIN'],
 0282                      'L_CONFIG'        => $user->lang[$lang . '_CONFIG'],
 0283                      'L_URL'            => $user->lang[$lang . '_URL'],
 0284                      'L_LOCATION'    => $user->lang[$lang . '_LOCATION'],
 0285                      'L_WIDTH'        => $user->lang[$lang . '_WIDTH'],
 0286                      'L_HEIGHT'        => $user->lang[$lang . '_HEIGHT'],
 0287                      'L_ORDER'        => $user->lang[$lang . '_ORDER'],
 0288                      'L_NO_ICONS'    => $user->lang['NO_' . $lang . '_' . strtoupper($action)],
 0289   
 0290                      'COLSPAN'        => $colspan,
 0291                      'ID'            => $icon_id,
 0292   
 0293                      'U_BACK'        => $this->u_action,
 0294                      'U_ACTION'        => $this->u_action . '&amp;action=' . (($action == 'add') ? 'create' : 'modify'),
 0295                  ));
 0296   
 0297                  foreach ($data as $img => $img_row)
 0298                  {
 0299                      $template->assign_block_vars('items', array(
 0300                          'IMG'        => $img,
 0301                          'A_IMG'        => addslashes($img),
 0302                          'IMG_SRC'    => $phpbb_root_path . $img_path . '/' . $img,
 0303   
 0304                          'CODE'        => ($mode == 'smilies' && isset($img_row['code'])) ? $img_row['code'] : '',
 0305                          'EMOTION'    => ($mode == 'smilies' && isset($img_row['emotion'])) ? $img_row['emotion'] : '',
 0306   
 0307                          'S_ID'                => (isset($img_row[$fields . '_id'])) ? true : false,
 0308                          'ID'                => (isset($img_row[$fields . '_id'])) ? $img_row[$fields . '_id'] : 0,
 0309                          'WIDTH'                => (!empty($img_row[$fields .'_width'])) ? $img_row[$fields .'_width'] : $img_row['width'],
 0310                          'HEIGHT'            => (!empty($img_row[$fields .'_height'])) ? $img_row[$fields .'_height'] : $img_row['height'],
 0311                          'TEXT_ALT'            => ($mode == 'icons' && !empty($img_row['icons_alt'])) ? $img_row['icons_alt'] : $img,
 0312                          'ALT'                => ($mode == 'icons' && !empty($img_row['icons_alt'])) ? $img_row['icons_alt'] : '',
 0313                          'POSTING_CHECKED'    => (!empty($img_row['display_on_posting']) || $action == 'add') ? ' checked="checked"' : '',
 0314                      ));
 0315                  }
 0316   
 0317                  // Ok, another row for adding an addition code for a pre-existing image...
 0318                  if ($action == 'add' && $mode == 'smilies' && count($smilies))
 0319                  {
 0320                      $template->assign_vars(array(
 0321                          'S_ADD_CODE'        => true,
 0322   
 0323                          'S_IMG_OPTIONS'        => $smiley_options,
 0324   
 0325                          'S_ADD_ORDER_LIST_DISPLAY'        => $add_order_list . $add_order_lists[1],
 0326                          'S_ADD_ORDER_LIST_UNDISPLAY'    => $add_order_list . $add_order_lists[0],
 0327   
 0328                          'IMG_SRC'            => $phpbb_root_path . $img_path . '/' . $default_row['smiley_url'],
 0329                          'IMG_PATH'            => $img_path,
 0330   
 0331                          'CODE'                => $default_row['code'],
 0332                          'EMOTION'            => $default_row['emotion'],
 0333   
 0334                          'WIDTH'                => $default_row['smiley_width'],
 0335                          'HEIGHT'            => $default_row['smiley_height'],
 0336                      ));
 0337                  }
 0338   
 0339                  return;
 0340   
 0341              break;
 0342   
 0343              case 'create':
 0344              case 'modify':
 0345   
 0346                  if (!check_form_key($form_key))
 0347                  {
 0348                      trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
 0349                  }
 0350   
 0351                  // Get items to create/modify
 0352                  $images = (isset($_POST['image'])) ? array_keys($request->variable('image', array('' => 0))) : array();
 0353   
 0354                  // Now really get the items
 0355                  $image_id        = (isset($_POST['id'])) ? $request->variable('id', array('' => 0)) : array();
 0356                  $image_order    = (isset($_POST['order'])) ? $request->variable('order', array('' => 0)) : array();
 0357                  $image_width    = (isset($_POST['width'])) ? $request->variable('width', array('' => 0)) : array();
 0358                  $image_height    = (isset($_POST['height'])) ? $request->variable('height', array('' => 0)) : array();
 0359                  $image_add        = (isset($_POST['add_img'])) ? $request->variable('add_img', array('' => 0)) : array();
 0360                  $image_emotion    = $request->variable('emotion', array('' => ''), true);
 0361                  $image_code        = $request->variable('code', array('' => ''), true);
 0362                  $image_alt        = ($request->is_set_post('alt')) ? $request->variable('alt', array('' => ''), true) : array();
 0363                  $image_display_on_posting = (isset($_POST['display_on_posting'])) ? $request->variable('display_on_posting', array('' => 0)) : array();
 0364   
 0365                  // Ok, add the relevant bits if we are adding new codes to existing emoticons...
 0366                  if ($request->variable('add_additional_code', false, false, \phpbb\request\request_interface::POST))
 0367                  {
 0368                      $add_image            = $request->variable('add_image', '');
 0369                      $add_code            = $request->variable('add_code', '', true);
 0370                      $add_emotion        = $request->variable('add_emotion', '', true);
 0371   
 0372                      if ($add_image && $add_emotion && $add_code)
 0373                      {
 0374                          $images[] = $add_image;
 0375                          $image_add[$add_image] = true;
 0376   
 0377                          $image_code[$add_image] = $add_code;
 0378                          $image_emotion[$add_image] = $add_emotion;
 0379                          $image_width[$add_image] = $request->variable('add_width', 0);
 0380                          $image_height[$add_image] = $request->variable('add_height', 0);
 0381   
 0382                          if ($request->variable('add_display_on_posting', false, false, \phpbb\request\request_interface::POST))
 0383                          {
 0384                              $image_display_on_posting[$add_image] = 1;
 0385                          }
 0386   
 0387                          $image_order[$add_image] = $request->variable('add_order', 0);
 0388                      }
 0389                  }
 0390   
 0391                  if ($mode == 'smilies' && $action == 'create')
 0392                  {
 0393                      $smiley_count = $this->item_count($table);
 0394   
 0395                      $addable_smileys_count = count($images);
 0396                      foreach ($images as $image)
 0397                      {
 0398                          if (!isset($image_add[$image]))
 0399                          {
 0400                              --$addable_smileys_count;
 0401                          }
 0402                      }
 0403   
 0404                      if ($smiley_count + $addable_smileys_count > SMILEY_LIMIT)
 0405                      {
 0406                          trigger_error($user->lang('TOO_MANY_SMILIES', SMILEY_LIMIT) . adm_back_link($this->u_action), E_USER_WARNING);
 0407                      }
 0408                  }
 0409   
 0410                  $icons_updated = 0;
 0411                  $errors = array();
 0412                  foreach ($images as $image)
 0413                  {
 0414                      if ($mode == 'smilies' && ($image_emotion[$image] == '' || $image_code[$image] == ''))
 0415                      {
 0416                          $errors[$image] = 'SMILIE_NO_' . (($image_emotion[$image] == '') ? 'EMOTION' : 'CODE');
 0417                      }
 0418                      else if ($action == 'create' && !isset($image_add[$image]))
 0419                      {
 0420                          // skip images where add wasn't checked
 0421                      }
 0422                      else if (!file_exists($phpbb_root_path . $img_path . '/' . $image))
 0423                      {
 0424                          $errors[$image] = 'SMILIE_NO_FILE';
 0425                      }
 0426                      else
 0427                      {
 0428                          if ($image_width[$image] == 0 || $image_height[$image] == 0)
 0429                          {
 0430                              $img_size = getimagesize($phpbb_root_path . $img_path . '/' . $image);
 0431                              $image_width[$image] = $img_size[0];
 0432                              $image_height[$image] = $img_size[1];
 0433                          }
 0434   
 0435                          // Adjust image width/height for icons
 0436                          if ($mode == 'icons')
 0437                          {
 0438                              if ($image_width[$image] > 127 && $image_width[$image] > $image_height[$image])
 0439                              {
 0440                                  $image_height[$image] = (int) ($image_height[$image] * (127 / $image_width[$image]));
 0441                                  $image_width[$image] = 127;
 0442                              }
 0443                              else if ($image_height[$image] > 127)
 0444                              {
 0445                                  $image_width[$image] = (int) ($image_width[$image] * (127 / $image_height[$image]));
 0446                                  $image_height[$image] = 127;
 0447                              }
 0448                          }
 0449   
 0450                          $img_sql = array(
 0451                              $fields . '_url'        => $image,
 0452                              $fields . '_width'        => $image_width[$image],
 0453                              $fields . '_height'        => $image_height[$image],
 0454                              'display_on_posting'    => (isset($image_display_on_posting[$image])) ? 1 : 0,
 0455                          );
 0456   
 0457                          if ($mode == 'smilies')
 0458                          {
 0459                              $img_sql = array_merge($img_sql, array(
 0460                                  'emotion'    => $image_emotion[$image],
 0461                                  'code'        => $image_code[$image])
 0462                              );
 0463                          }
 0464   
 0465                          if ($mode == 'icons')
 0466                          {
 0467                              $img_sql = array_merge($img_sql, array(
 0468                                  'icons_alt'    => $image_alt[$image])
 0469                              );
 0470                          }
 0471   
 0472                          // Image_order holds the 'new' order value
 0473                          if (!empty($image_order[$image]))
 0474                          {
 0475                              $img_sql = array_merge($img_sql, array(
 0476                                  $fields . '_order'    =>    $image_order[$image])
 0477                              );
 0478   
 0479                              // Since we always add 'after' an item, we just need to increase all following + the current by one
 0480                              $sql = "UPDATE $table
 0481                                  SET {$fields}_order = {$fields}_order + 1
 0482                                  WHERE {$fields}_order >= {$image_order[$image]}";
 0483                              $db->sql_query($sql);
 0484   
 0485                              // If we adjust the order, we need to adjust all other orders too - they became inaccurate...
 0486                              foreach ($image_order as $_image => $_order)
 0487                              {
 0488                                  if ($_image == $image)
 0489                                  {
 0490                                      continue;
 0491                                  }
 0492   
 0493                                  if ($_order >= $image_order[$image])
 0494                                  {
 0495                                      $image_order[$_image]++;
 0496                                  }
 0497                              }
 0498                          }
 0499   
 0500                          if ($action == 'modify'  && !empty($image_id[$image]))
 0501                          {
 0502                              $sql = "UPDATE $table
 0503                                  SET " . $db->sql_build_array('UPDATE', $img_sql) . "
 0504                                  WHERE {$fields}_id = " . $image_id[$image];
 0505                              $db->sql_query($sql);
 0506                              $icons_updated++;
 0507                          }
 0508                          else if ($action !== 'modify')
 0509                          {
 0510                              $sql = "INSERT INTO $table " . $db->sql_build_array('INSERT', $img_sql);
 0511                              $db->sql_query($sql);
 0512                              $icons_updated++;
 0513                          }
 0514   
 0515                      }
 0516                  }
 0517   
 0518                  $cache->destroy('_icons');
 0519                  $cache->destroy('sql', $table);
 0520                  $phpbb_container->get('text_formatter.cache')->invalidate();
 0521   
 0522                  $level = ($icons_updated) ? E_USER_NOTICE : E_USER_WARNING;
 0523                  $errormsgs = '';
 0524                  foreach ($errors as $img => $error)
 0525                  {
 0526                      $errormsgs .= '<br />' . sprintf($user->lang[$error], $img);
 0527                  }
 0528                  if ($action == 'modify')
 0529                  {
 0530                      trigger_error($user->lang($lang . '_EDITED', $icons_updated) . $errormsgs . adm_back_link($this->u_action), $level);
 0531                  }
 0532                  else
 0533                  {
 0534                      trigger_error($user->lang($lang . '_ADDED', $icons_updated) . $errormsgs . adm_back_link($this->u_action), $level);
 0535                  }
 0536   
 0537              break;
 0538   
 0539              case 'import':
 0540   
 0541                  $pak = $request->variable('pak', '');
 0542                  $current = $request->variable('current', '');
 0543   
 0544                  if ($pak != '')
 0545                  {
 0546                      $order = 0;
 0547   
 0548                      if (!check_form_key($form_key))
 0549                      {
 0550                          trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
 0551                      }
 0552   
 0553                      if (!($pak_ary = @file($phpbb_root_path . $img_path . '/' . utf8_basename($pak))))
 0554                      {
 0555                          trigger_error($user->lang['PAK_FILE_NOT_READABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
 0556                      }
 0557   
 0558                      // Make sure the pak_ary is valid
 0559                      foreach ($pak_ary as $pak_entry)
 0560                      {
 0561                          if (preg_match_all("#'(.*?)', ?#", $pak_entry, $data))
 0562                          {
 0563                              if ((count($data[1]) != 4 && $mode == 'icons') ||
 0564                                  ((count($data[1]) != 6 || (empty($data[1][4]) || empty($data[1][5]))) && $mode == 'smilies' ))
 0565                              {
 0566                                  trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
 0567                              }
 0568                          }
 0569                          else
 0570                          {
 0571                              trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
 0572                          }
 0573                      }
 0574   
 0575                      // The user has already selected a smilies_pak file
 0576                      if ($current == 'delete')
 0577                      {
 0578                          switch ($db->get_sql_layer())
 0579                          {
 0580                              case 'sqlite3':
 0581                                  $db->sql_query('DELETE FROM ' . $table);
 0582                              break;
 0583   
 0584                              default:
 0585                                  $db->sql_query('TRUNCATE TABLE ' . $table);
 0586                              break;
 0587                          }
 0588   
 0589                          switch ($mode)
 0590                          {
 0591                              case 'smilies':
 0592                              break;
 0593   
 0594                              case 'icons':
 0595                                  // Reset all icon_ids
 0596                                  $db->sql_query('UPDATE ' . TOPICS_TABLE . ' SET icon_id = 0');
 0597                                  $db->sql_query('UPDATE ' . POSTS_TABLE . ' SET icon_id = 0');
 0598                              break;
 0599                          }
 0600                      }
 0601                      else
 0602                      {
 0603                          $cur_img = array();
 0604   
 0605                          $field_sql = ($mode == 'smilies') ? 'code' : 'icons_url';
 0606   
 0607                          $sql = "SELECT $field_sql
 0608                              FROM $table";
 0609                          $result = $db->sql_query($sql);
 0610   
 0611                          while ($row = $db->sql_fetchrow($result))
 0612                          {
 0613                              ++$order;
 0614                              $cur_img[$row[$field_sql]] = 1;
 0615                          }
 0616                          $db->sql_freeresult($result);
 0617                      }
 0618   
 0619                      if ($mode == 'smilies')
 0620                      {
 0621                          $smiley_count = $this->item_count($table);
 0622                          if ($smiley_count + count($pak_ary) > SMILEY_LIMIT)
 0623                          {
 0624                              trigger_error($user->lang('TOO_MANY_SMILIES', SMILEY_LIMIT) . adm_back_link($this->u_action), E_USER_WARNING);
 0625                          }
 0626                      }
 0627   
 0628                      foreach ($pak_ary as $pak_entry)
 0629                      {
 0630                          $data = array();
 0631                          if (preg_match_all("#'(.*?)', ?#", $pak_entry, $data))
 0632                          {
 0633                              if ((count($data[1]) != 4 && $mode == 'icons') ||
 0634                                  (count($data[1]) != 6 && $mode == 'smilies'))
 0635                              {
 0636                                  trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
 0637                              }
 0638   
 0639                              // Stripslash here because it got addslashed before... (on export)
 0640                              $img = stripslashes($data[1][0]);
 0641                              $width = stripslashes($data[1][1]);
 0642                              $height = stripslashes($data[1][2]);
 0643                              $display_on_posting = stripslashes($data[1][3]);
 0644   
 0645                              if (isset($data[1][4]) && isset($data[1][5]))
 0646                              {
 0647                                  $emotion = stripslashes($data[1][4]);
 0648                                  $code = stripslashes($data[1][5]);
 0649                              }
 0650   
 0651                              if ($current == 'replace' &&
 0652                                  (($mode == 'smilies' && !empty($cur_img[$code])) ||
 0653                                  ($mode == 'icons' && !empty($cur_img[$img]))))
 0654                              {
 0655                                  $replace_sql = ($mode == 'smilies') ? $code : $img;
 0656                                  $sql = array(
 0657                                      $fields . '_url'        => utf8_substr(rawurlencode($img), 0, 50),
 0658                                      $fields . '_height'        => (int) $height,
 0659                                      $fields . '_width'        => (int) $width,
 0660                                      'display_on_posting'    => (int) $display_on_posting,
 0661                                  );
 0662   
 0663                                  if ($mode == 'smilies')
 0664                                  {
 0665                                      $sql = array_merge($sql, array(
 0666                                          'emotion'                => $emotion,
 0667                                      ));
 0668                                  }
 0669   
 0670                                  $sql = "UPDATE $table SET " . $db->sql_build_array('UPDATE', $sql) . "
 0671                                      WHERE $field_sql = '" . $db->sql_escape($replace_sql) . "'";
 0672                                  $db->sql_query($sql);
 0673                              }
 0674                              else
 0675                              {
 0676                                  ++$order;
 0677   
 0678                                  $sql = array(
 0679                                      $fields . '_url'    => utf8_substr(rawurlencode($img), 0, 50),
 0680                                      $fields . '_height'    => (int) $height,
 0681                                      $fields . '_width'    => (int) $width,
 0682                                      $fields . '_order'    => (int) $order,
 0683                                      'display_on_posting'=> (int) $display_on_posting,
 0684                                  );
 0685   
 0686                                  if ($mode == 'smilies')
 0687                                  {
 0688                                      $sql = array_merge($sql, array(
 0689                                          'code'                => $code,
 0690                                          'emotion'            => $emotion,
 0691                                      ));
 0692                                  }
 0693                                  $db->sql_query("INSERT INTO $table " . $db->sql_build_array('INSERT', $sql));
 0694                              }
 0695                          }
 0696                      }
 0697   
 0698                      $cache->destroy('_icons');
 0699                      $cache->destroy('sql', $table);
 0700                      $phpbb_container->get('text_formatter.cache')->invalidate();
 0701   
 0702                      trigger_error($user->lang[$lang . '_IMPORT_SUCCESS'] . adm_back_link($this->u_action));
 0703                  }
 0704                  else
 0705                  {
 0706                      $pak_options = '';
 0707   
 0708                      foreach ($_paks as $pak)
 0709                      {
 0710                          $pak_options .= '<option value="' . $pak . '">' . htmlspecialchars($pak, ENT_COMPAT) . '</option>';
 0711                      }
 0712   
 0713                      $template->assign_vars(array(
 0714                          'S_CHOOSE_PAK'        => true,
 0715                          'S_PAK_OPTIONS'        => $pak_options,
 0716   
 0717                          'L_TITLE'            => $user->lang['ACP_' . $lang],
 0718                          'L_EXPLAIN'            => $user->lang['ACP_' . $lang . '_EXPLAIN'],
 0719                          'L_NO_PAK_OPTIONS'    => $user->lang['NO_' . $lang . '_PAK'],
 0720                          'L_CURRENT'            => $user->lang['CURRENT_' . $lang],
 0721                          'L_CURRENT_EXPLAIN'    => $user->lang['CURRENT_' . $lang . '_EXPLAIN'],
 0722                          'L_IMPORT_SUBMIT'    => $user->lang['IMPORT_' . $lang],
 0723   
 0724                          'U_BACK'        => $this->u_action,
 0725                          'U_ACTION'        => $this->u_action . '&amp;action=import',
 0726                          )
 0727                      );
 0728                  }
 0729              break;
 0730   
 0731              case 'export':
 0732   
 0733                  $this->page_title = 'EXPORT_' . $lang;
 0734                  $this->tpl_name = 'message_body';
 0735   
 0736                  $template->assign_vars(array(
 0737                      'MESSAGE_TITLE'        => $user->lang['EXPORT_' . $lang],
 0738                      'MESSAGE_TEXT'        => sprintf($user->lang['EXPORT_' . $lang . '_EXPLAIN'], '<a href="' . $this->u_action . '&amp;action=send&amp;hash=' . generate_link_hash('acp_icons') . '">', '</a>'),
 0739   
 0740                      'S_USER_NOTICE'        => true,
 0741                      )
 0742                  );
 0743   
 0744                  return;
 0745   
 0746              break;
 0747   
 0748              case 'send':
 0749   
 0750                  if (!check_link_hash($request->variable('hash', ''), 'acp_icons'))
 0751                  {
 0752                      trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
 0753                  }
 0754   
 0755                  $sql = "SELECT *
 0756                      FROM $table
 0757                      ORDER BY {$fields}_order";
 0758                  $result = $db->sql_query($sql);
 0759   
 0760                  $pak = '';
 0761                  while ($row = $db->sql_fetchrow($result))
 0762                  {
 0763                      $pak .= "'" . addslashes($row[$fields . '_url']) . "', ";
 0764                      $pak .= "'" . addslashes($row[$fields . '_width']) . "', ";
 0765                      $pak .= "'" . addslashes($row[$fields . '_height']) . "', ";
 0766                      $pak .= "'" . addslashes($row['display_on_posting']) . "', ";
 0767   
 0768                      if ($mode == 'smilies')
 0769                      {
 0770                          $pak .= "'" . addslashes($row['emotion']) . "', ";
 0771                          $pak .= "'" . addslashes($row['code']) . "', ";
 0772                      }
 0773   
 0774                      $pak .= "\n";
 0775                  }
 0776                  $db->sql_freeresult($result);
 0777   
 0778                  if ($pak != '')
 0779                  {
 0780                      garbage_collection();
 0781   
 0782                      header('Cache-Control: public');
 0783   
 0784                      // Send out the Headers
 0785                      header('Content-Type: text/x-delimtext; name="' . $mode . '.pak"');
 0786                      header('Content-Disposition: inline; filename="' . $mode . '.pak"');
 0787                      echo $pak;
 0788   
 0789                      flush();
 0790                      exit;
 0791                  }
 0792                  else
 0793                  {
 0794                      trigger_error($user->lang['NO_' . strtoupper($fields) . '_EXPORT'] . adm_back_link($this->u_action), E_USER_WARNING);
 0795                  }
 0796   
 0797              break;
 0798   
 0799              case 'delete':
 0800   
 0801                  if (confirm_box(true))
 0802                  {
 0803                      $sql = "DELETE FROM $table
 0804                          WHERE {$fields}_id = $icon_id";
 0805                      $db->sql_query($sql);
 0806   
 0807                      switch ($mode)
 0808                      {
 0809                          case 'smilies':
 0810                          break;
 0811   
 0812                          case 'icons':
 0813                              // Reset appropriate icon_ids
 0814                              $db->sql_query('UPDATE ' . TOPICS_TABLE . "
 0815                                  SET icon_id = 0
 0816                                  WHERE icon_id = $icon_id");
 0817   
 0818                              $db->sql_query('UPDATE ' . POSTS_TABLE . "
 0819                                  SET icon_id = 0
 0820                                  WHERE icon_id = $icon_id");
 0821                          break;
 0822                      }
 0823   
 0824                      $notice = $user->lang[$lang . '_DELETED'];
 0825   
 0826                      $cache->destroy('_icons');
 0827                      $cache->destroy('sql', $table);
 0828                      $phpbb_container->get('text_formatter.cache')->invalidate();
 0829   
 0830                      if ($request->is_ajax())
 0831                      {
 0832                          $json_response = new \phpbb\json_response;
 0833                          $json_response->send(array(
 0834                              'MESSAGE_TITLE'    => $user->lang['INFORMATION'],
 0835                              'MESSAGE_TEXT'    => $notice,
 0836                              'REFRESH_DATA'    => array(
 0837                                  'time'    => 3
 0838                              )
 0839                          ));
 0840                      }
 0841                  }
 0842                  else
 0843                  {
 0844                      confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
 0845                          'i'            => $id,
 0846                          'mode'        => $mode,
 0847                          'id'        => $icon_id,
 0848                          'action'    => 'delete',
 0849                      )));
 0850                  }
 0851   
 0852              break;
 0853   
 0854              case 'move_up':
 0855              case 'move_down':
 0856   
 0857                  if (!check_link_hash($request->variable('hash', ''), 'acp_icons'))
 0858                  {
 0859                      trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
 0860                  }
 0861   
 0862                  // Get current order id...
 0863                  $sql = "SELECT {$fields}_order as current_order
 0864                      FROM $table
 0865                      WHERE {$fields}_id = $icon_id";
 0866                  $result = $db->sql_query($sql);
 0867                  $current_order = (int) $db->sql_fetchfield('current_order');
 0868                  $db->sql_freeresult($result);
 0869   
 0870                  if ($current_order == 0 && $action == 'move_up')
 0871                  {
 0872                      break;
 0873                  }
 0874   
 0875                  // on move_down, switch position with next order_id...
 0876                  // on move_up, switch position with previous order_id...
 0877                  $switch_order_id = ($action == 'move_down') ? $current_order + 1 : $current_order - 1;
 0878   
 0879                  //
 0880                  $sql = "UPDATE $table
 0881                      SET {$fields}_order = $current_order
 0882                      WHERE {$fields}_order = $switch_order_id
 0883                          AND {$fields}_id <> $icon_id";
 0884                  $db->sql_query($sql);
 0885                  $move_executed = (bool) $db->sql_affectedrows();
 0886   
 0887                  // Only update the other entry too if the previous entry got updated
 0888                  if ($move_executed)
 0889                  {
 0890                      $sql = "UPDATE $table
 0891                          SET {$fields}_order = $switch_order_id
 0892                          WHERE {$fields}_order = $current_order
 0893                              AND {$fields}_id = $icon_id";
 0894                      $db->sql_query($sql);
 0895                  }
 0896   
 0897                  $cache->destroy('_icons');
 0898                  $cache->destroy('sql', $table);
 0899                  $phpbb_container->get('text_formatter.cache')->invalidate();
 0900   
 0901                  if ($request->is_ajax())
 0902                  {
 0903                      $json_response = new \phpbb\json_response;
 0904                      $json_response->send(array(
 0905                          'success'    => $move_executed,
 0906                      ));
 0907                  }
 0908   
 0909              break;
 0910          }
 0911   
 0912          // By default, check that image_order is valid and fix it if necessary
 0913          $sql = "SELECT {$fields}_id AS order_id, {$fields}_order AS fields_order
 0914              FROM $table
 0915              ORDER BY display_on_posting DESC, {$fields}_order";
 0916          $result = $db->sql_query($sql);
 0917   
 0918          if ($row = $db->sql_fetchrow($result))
 0919          {
 0920              $order = 0;
 0921              do
 0922              {
 0923                  ++$order;
 0924                  if ($row['fields_order'] != $order)
 0925                  {
 0926                      $db->sql_query("UPDATE $table
 0927                          SET {$fields}_order = $order
 0928                          WHERE {$fields}_id = " . $row['order_id']);
 0929                  }
 0930              }
 0931              while ($row = $db->sql_fetchrow($result));
 0932          }
 0933          $db->sql_freeresult($result);
 0934   
 0935          $template->assign_vars(array(
 0936              'L_TITLE'            => $user->lang['ACP_' . $lang],
 0937              'L_EXPLAIN'            => $user->lang['ACP_' . $lang . '_EXPLAIN'],
 0938              'L_IMPORT'            => $user->lang['IMPORT_' . $lang],
 0939              'L_EXPORT'            => $user->lang['EXPORT_' . $lang],
 0940              'L_NOT_DISPLAYED'    => $user->lang[$lang . '_NOT_DISPLAYED'],
 0941              'L_ICON_ADD'        => $user->lang['ADD_' . $lang],
 0942              'L_ICON_EDIT'        => $user->lang['EDIT_' . $lang],
 0943   
 0944              'NOTICE'            => $notice,
 0945              'COLSPAN'            => ($mode == 'smilies') ? 5 : 3,
 0946   
 0947              'S_SMILIES'            => ($mode == 'smilies') ? true : false,
 0948   
 0949              'U_ACTION'            => $this->u_action,
 0950              'U_IMPORT'            => $this->u_action . '&amp;action=import',
 0951              'U_EXPORT'            => $this->u_action . '&amp;action=export',
 0952              )
 0953          );
 0954   
 0955          /* @var $pagination \phpbb\pagination */
 0956          $pagination = $phpbb_container->get('pagination');
 0957          $pagination_start = $request->variable('start', 0);
 0958          $spacer = false;
 0959   
 0960          $item_count = $this->item_count($table);
 0961   
 0962          $sql = "SELECT *
 0963              FROM $table
 0964              ORDER BY {$fields}_order ASC";
 0965          $result = $db->sql_query_limit($sql, $config['smilies_per_page'], $pagination_start);
 0966   
 0967          while ($row = $db->sql_fetchrow($result))
 0968          {
 0969              $alt_text = ($mode == 'smilies') ? $row['code'] : (($mode == 'icons' && !empty($row['icons_alt'])) ? $row['icons_alt'] : $row['icons_url']);
 0970   
 0971              $template->assign_block_vars('items', array(
 0972                  'S_SPACER'        => (!$spacer && !$row['display_on_posting']) ? true : false,
 0973                  'ALT_TEXT'        => $alt_text,
 0974                  'IMG_SRC'        => $phpbb_root_path . $img_path . '/' . $row[$fields . '_url'],
 0975                  'WIDTH'            => $row[$fields . '_width'],
 0976                  'HEIGHT'        => $row[$fields . '_height'],
 0977                  'CODE'            => (isset($row['code'])) ? $row['code'] : '',
 0978                  'EMOTION'        => (isset($row['emotion'])) ? $row['emotion'] : '',
 0979                  'U_EDIT'        => $this->u_action . '&amp;action=edit&amp;id=' . $row[$fields . '_id'],
 0980                  'U_DELETE'        => $this->u_action . '&amp;action=delete&amp;id=' . $row[$fields . '_id'],
 0981                  'U_MOVE_UP'        => $this->u_action . '&amp;action=move_up&amp;id=' . $row[$fields . '_id'] . '&amp;start=' . $pagination_start . '&amp;hash=' . generate_link_hash('acp_icons'),
 0982                  'U_MOVE_DOWN'    => $this->u_action . '&amp;action=move_down&amp;id=' . $row[$fields . '_id'] . '&amp;start=' . $pagination_start . '&amp;hash=' . generate_link_hash('acp_icons'),
 0983              ));
 0984   
 0985              if (!$spacer && !$row['display_on_posting'])
 0986              {
 0987                  $spacer = true;
 0988              }
 0989          }
 0990          $db->sql_freeresult($result);
 0991   
 0992          $pagination->generate_template_pagination($this->u_action, 'pagination', 'start', $item_count, $config['smilies_per_page'], $pagination_start);
 0993      }
 0994   
 0995      /**
 0996       * Returns the count of smilies or icons in the database
 0997       *
 0998       * @param string $table The table of items to count.
 0999       * @return int number of items
 1000       */
 1001      /* private */ function item_count($table)
 1002      {
 1003          global $db;
 1004   
 1005          $sql = "SELECT COUNT(*) AS item_count
 1006              FROM $table";
 1007          $result = $db->sql_query($sql);
 1008          $item_count = (int) $db->sql_fetchfield('item_count');
 1009          $db->sql_freeresult($result);
 1010   
 1011          return $item_count;
 1012      }
 1013  }
 1014