将字符串内的图片元数据保存为图片

@param $content

@return mixed
350375
public static function recoverImg($content)
    {
        preg_match_all('/src="data:\s*image\/(\w+);base64,([^"]+)"/', $content, $match);

        $imgs = [];
        if(isset($match[2])){
            foreach($match[2] as $key => $data){
                $md5 = md5($data);

                if(isset($imgs[$md5])){
                    continue;
                }

                $ext = $match[1][$key];
                if($ext == 'jpeg'){
                    $ext = 'jpg';
                }

                $newImg = File::newFile($ext);

                $imgs[$md5] = $newImg;

                $content = str_replace($match[0][$key], 'src="' . Url::getStatic($newImg) .'"', $content);

                file_put_contents(Folder::getStatic($newImg), base64_decode($data));
            }
        }

        return [
            'content' => $content,
            'imgs' => $imgs,
        ];
    }
1025702
protected function getFullTextValues(Content $content)
    {
        $fullTextValues = [];
        foreach ($content->fields as $field) {
            $fieldDefinition = $this->contentTypeHandler->getFieldDefinition(
                $field->fieldDefinitionId, Content\Type::STATUS_DEFINED
            );
            if (!$fieldDefinition->isSearchable) {
                continue;
            }

            $value = $this->getFullTextFieldValue($field, $fieldDefinition);
            if (empty($value)) {
                continue;
            }

            $fullTextValues[] = new FullTextValue(
                [
                    'id' => $field->id,
                    'fieldDefinitionId' => $field->fieldDefinitionId,
                    'fieldDefinitionIdentifier' => $fieldDefinition->identifier,
                    'languageCode' => $field->languageCode,
                    'value' => !is_array($value) ? $value : implode(' ', $value),
                ]
            );
        }

        return $fullTextValues;
    }
1364588
public function extractContent($content)
    {
        $regex = '~^('
            . '---'                                  // $matches[1] start separator
            . "){1}[\r\n|\n]*(.*?)[\r\n|\n]+("       // $matches[2] front matter
            . '---'                                  // $matches[3] end separator
            . "){1}[\r\n|\n]*(.*)$~s";               // $matches[4] document content

        return preg_match($regex, $content, $matches) === 1 ? ltrim($matches[4]) : $content;
    }
447551
protected function _defaultData($content)
    {
        $content = @unserialize($content);
        if (empty($content) || !is_a($content, \stdClass::class)) {
            $content = new \stdClass;
        }
        $content->file = empty($content->file) ? '' : $content->file;
        $content->title = empty($content->title) ? '' : $content->title;
        return $content;
    }
25935
public function convert($content)
    {
        $result = strtr($content, $this->rules);
        return $this->correct($result);
    }
1070833
protected function _getContent($content)
    {
        if(!isset($content))
            return;

        if(is_array($content))
            return array_map(
                function ($value) {
                    return $this->_getContent($value);
                }, $content
            );

        switch(gettype($content)) {
            case 'string': case 'integer': case 'double': case 'float':
                return $content;
            break;
            case 'object':
                if('Closure' == get_class($content)) {
                    ob_start();
                    ob_clean();
                    $returned = $content($this->data);
                    $output = ob_get_clean();
                    if(isset($returned))
                        return $returned;
                    else
                        return $output;
                } elseif(isset($content->content))
                    return $content->content;
            break;
            default:
                throw new \InvalidArgumentException('wrong view content type : '.gettype($content));
        }
    }
278295
public function parseContent($content) {
        $dc = json_decode($content, true);

        $ret = [];

        foreach ($dc as $key => $content) {
            preg_match("/^(?P<type>[a-z0-9A-Z]*):(?P<path>(?P<id>[a-z0-9A-Z]*):(?P<field>[a-z0-9A-Z]*))$/", $key, $matches);

            $ret[] = [
                'type' => $matches['type'],
                'path' => $matches['path'],
                'id' => $matches['id'],
                'field' => $matches['field'],
                'content' => $content
            ];
        }

        return $ret;
    }
363758
public function writeCachedContent($content)
    {
        return $this->smarty->ext->_updateCache->writeCachedContent($this->cached, $this, $content);
    }
334010
protected function _replace($content)
    {
        $content = trim($content, "\r\n ");
        if (!$this->blocks) {
            return $content;
        }

        return strtr($content, $this->blocks);
    }
171960
protected function _defaultData($content)
    {
        $content = @unserialize($content);
        return (empty($content) || !is_array($content)) ? [] : $content;
    }
234598
private function storePageHandler($content)
    {
        try {
            return $this->storePageContent($content);
        } catch (\Throwable $t) {
            $this->log('', $t);
        } catch (\Exception $e) {
            $this->log('', $e);
        }

        return $content;
    }
1196925
public function sign($content) {
        if (is_array($content)) {
            $this->ignoreKeys = ['sign'];
            $content = $this->getSignContent($content);
        }
        if ($this->getSignType() == self::MD5) {
            return md5($content.$this->key);
        }
        return $this->getRsa()->sign($content);
    }
1205185
protected function _defaultData($content)
    {
        $content = @unserialize($content);
        if (empty($content) || !is_a($content, \stdClass::class)) {
            $content = new \stdClass;
        }
        $content->text = isset($content->text) ? $content->text : '';
        $content->colour = isset($content->colour) ? $content->colour : '';
        return $content;
    }
1149853
static public function getFileExt($content)
    {
        $types = array(
            255216 => 'jpg', 7173 => 'gif', 6677 => 'bmp', 13780 => 'png',
            7368   => 'mp3', 4838 => 'wma', 7784 => 'mid', 6063 => 'xml',
        );
        $typeInfo = @unpack("C2chars", substr($content, 0, 2));
        $typeCode = intval($typeInfo['chars1'] . $typeInfo['chars2']);
        return isset($types[$typeCode]) ? $types[$typeCode] : 'mp4';
    }
367077
public function decode_content($content) {
        if (!$content = $this->precheck_content($content)) { // Perform some prechecks
            return false;
        }
        // Iterate over all rules, chaining results
        foreach ($this->rules as $rule) {
            $content = $rule->decode($content);
        }
        return $content;
    }
824612
public function save($content)
    {
        $path = $this->buildPath();

        $this->createDir($path);
        file_put_contents($path, $content);

        if (!$this->extension) {
            $this->extension = $this->determineExtension($content);
        }

        if ($this->extension) {
            rename($path, $path . '.' . $this->extension);
            $path .= '.' . $this->extension;
        }

        return $path;
    }
271148
protected function parseResult($content)
    {
        $data = [];

        foreach (explode(static::ROW_DELIMITER, $content) as $row) {
            if (empty($row)) {
                continue;
            }

            $data[] = json_decode($row, true);
        }

        return $data;
    }