Пример #1
0
 /**
  * @return array[]
  * @throws CM_Exception
  */
 private static function _readEmoticonData()
 {
     /** @var CM_File[] $configurationFiles */
     $configurationFiles = [];
     /** @var CM_File[] $imageFiles */
     $imageFiles = [];
     $bootloader = CM_Bootloader::getInstance();
     foreach ($bootloader->getModules() as $namespace) {
         $emoticonDir = new CM_File(CM_Util::getModulePath($namespace) . 'layout/default/resource/img/emoticon/');
         foreach ($emoticonDir->listFiles(true) as $file) {
             $name = strtolower($file->getFileNameWithoutExtension());
             if ('json' === $file->getExtension()) {
                 $configurationFiles[$name] = $file;
             } else {
                 $imageFiles[$name] = $file;
             }
         }
     }
     $dataList = [];
     $codeList = [];
     foreach ($imageFiles as $name => $file) {
         $dataList[$name] = ['name' => $name, 'fileName' => $file->getFileName(), 'codes' => [":{$name}:"]];
         $codeList[":{$name}:"] = $name;
     }
     foreach ($configurationFiles as $name => $file) {
         $additionalCodes = CM_Params::jsonDecode($file->read())['additionalCodes'];
         foreach ($additionalCodes as $code) {
             if (!array_key_exists($code, $codeList)) {
                 $codeList[$code] = $name;
                 $dataList[$name]['codes'][] = $code;
             } else {
                 throw new CM_Exception('Emoticon codes overlap', null, ['overlapping emoticons' => [$name, $codeList[$code]], 'code' => $code]);
             }
         }
     }
     return $dataList;
 }