Apple_Exporter\Exporter::generate_json PHP Метод

generate_json() приватный Метод

Generate article.json contents. It does so by looping though all data, generating valid JSON and adding attachments to workspace/tmp directory.
private generate_json ( ) : string
Результат string The generated JSON for article.json
    private function generate_json()
    {
        // Base JSON
        $json = array('version' => '1.1', 'identifier' => 'post-' . $this->content_id(), 'language' => 'en', 'title' => $this->content_title());
        // Builders
        $json['documentStyle'] = $this->build_article_style();
        foreach ($this->builders as $name => $builder) {
            $arr = $builder->to_array();
            if ($arr) {
                $json[$name] = $arr;
            }
        }
        $json = apply_filters('apple_news_generate_json', $json, $this->content_id());
        $json = json_encode($json);
        // Check the JSON for unicode errors.
        // For now, we'll assume that multiple unicode characters in sequence
        // containing the  (\u00C2) indicate a problem as that has been the
        // most common indication of the issue.
        preg_match_all('/(\\\\u[0-9a-fA-F]{4}){2,}/', $json, $matches);
        if (!empty($matches[0])) {
            // Get a unique list of character sequences
            $character_sequences = array_unique($matches[0]);
            foreach ($character_sequences as &$sequence) {
                // Convert back to a display format
                $sequence = json_decode('{ "value":"' . $sequence . '"}');
                $sequence = $sequence->value;
            }
            $this->workspace->log_error('json_errors', sprintf(__('Invalid unicode character sequences were found that could cause display issues on Apple News: %s', 'apple-news'), implode(', ', $character_sequences)));
        }
        return $json;
    }