【问题标题】:Apple News API formatting with Chapter three in PHP使用 PHP 中的第三章格式化 Apple News API
【发布时间】:2020-10-21 21:59:57
【问题描述】:

我必须让这样的 JSON 被 Apple 新闻格式所接受。

    {
  "version": "1.7",
  "identifier": "SampleArticle",
  "language": "en",
  "title": "Apple News App",
  "subtitle": "A look at the features of the News iOS app",
  "layout": {
    "columns": 20,
    "width": 1024,
    "margin": 60,
    "gutter": 20
  },
  "components": [
    {
      "role": "title",
      "text": "Apple News App",
      "textStyle": "title"
    },
    {
      "role": "body",
      "text": "The Apple News Format allows publishers to craft beautiful editorial layouts. Galleries, audio, video, and fun interactions like animation make stories spring to life."
    },
    {
      "role": "photo",
      "URL": "bundle://image.jpg"
    }
  ],
  "documentStyle": {
    "backgroundColor": "#F7F7F7"
  },
  "componentTextStyles": {
    "default": {
      "fontName": "Helvetica",
      "fontSize": 13,
      "linkStyle": {
        "textColor": "#428bca"
      }
    },
    "title": {
      "fontName": "Helvetica-Bold",
      "fontSize": 30,
      "hyphenation": false
    },
    "default-body": {
      "fontName": "Helvetica",
      "fontSize": 13
    }
  }
}

到目前为止我尝试过的是 苹果新闻第三章 formating and publishing Apple news API PHP class 文档在这里 Documenmtnion for chapter three Apple news API

Link for the Detailed document for what i've tried and out put

require_once __DIR__ . '/vendor/autoload.php';
use ChapterThree\AppleNewsAPI\Document;
use ChapterThree\AppleNewsAPI\Document\Components\Body;
use ChapterThree\AppleNewsAPI\Document\Layouts\Layout;
use ChapterThree\AppleNewsAPI\Document\Styles\ComponentTextStyle;
use ChapterThree\AppleNewsAPI\Document\Base;
use ChapterThree\AppleNewsAPI\Document\Styles\Text;
use ChapterThree\AppleNewsAPI\Document\Styles\ComponentTextStyleTest;
use ChapterThree\AppleNewsAPI\Document\Styles\InlineTextStyle;
use ChapterThree\AppleNewsAPI\Document\Styles\Border;
use ChapterThree\AppleNewsAPI\Document\Styles\TextStyle;
use ChapterThree\AppleNewsAPI\Document\Components;

使用这个类来获取 html 内容的格式。它应该必须返回 JSON 格式。我之前分享过,但它只返回样式,而不是文本。有时为空 JSON 格式。

$articleBody = '<p style="font-size:13;border-top:1px;text-align:center">A quick brown Fox jumps over the Alzy Dog</p>'; ## with inline styling tags

类自带示例代码

$title_id = uniqid();
$obj = new Document(uniqid(), $articleTitle, 'en', new Layout(7, 1024));
$obj->addComponent(new Body($articleBody))
     ->addComponentTextStyle('default', new ComponentTextStyle());
##that outputs only plain text in the right format. 
##but not the inline HTML content.
 <?php  # differnent object names for different function
$obj3 = new Body($articleBody);   
$obj3->getFormat();

$json = $obj3->json();
echo $json;
#also tried to get border 
$newobj = new Border(new Body($articleBody));
echo $newobj->getTop();
# and
$newobj2 = new InlineTextStyle(12,144,'center');
$newobj2-> getTextStyle(new Body($articleBody));
?>
#But none of them get me to actuall feed format. 
#Do anybody know any format or class which will convert HTML content. to #apple news format in PHP. 


$content = '<p><em>PopOff Marketing, a top-quality Search Engine Optimization and Search Engine Marketing Agency, is launching a new rebrand and website that is expected to be finished on October 12th! The agency specializes in a wide range of support and solutions tailored to specific business needs in this current competitive market. PopOff Marketing provides the best digital marketing services at affordable prices to help your business literally pop off!</em></p>
<p><em>FOR IMMEDIATE RELEASE</em></p>


<a href="https://www.popoffmarketing.com/about/" target="_blank" rel="noopener noreferrer">https://www.popoffmarketing.com/about/</a>.</p>
<p><strong>Contact Info:</strong></p>
<p>Chris Corigliano<br />
PopOff Marketing<br />
8660 Homeplace Dr.<br />
Office: (844) 934-0590</p>
<div id="fd7209aa303fa1c07bb197a83d101b48" class="trk"><img loading="lazy" class="aligncenter" src="https://demo.popoffmarketing.com/wp-content/uploads/2020/09/PM-Logo-Big-Prints.png" alt="PopOff Marketing" width="250" height="250" /></div>
<div></div>
<div><em>Originally Posted On: <a href="https://syndication.cloud/popoff-marketing-pops-off-their-newest-rebrand-to-launch-october-12th/">https://syndication.cloud/popoff-marketing-pops-off-their-newest-rebrand-to-launch-october-12th/</a></em></div>';

如何将此内容(提要)转换为问题顶部给出的 JSON 格式?

【问题讨论】:

    标签: php html json api formatting


    【解决方案1】:

    您需要使用Markdown 类将其转换为组件。

    这样的事情应该可以工作:

    use ChapterThree\AppleNewsAPI\Document\Markdown;
    use ChapterThree\AppleNewsAPI\Document\Components\Body;
    
    $markdown = new Markdown();
    $text = $markdown->convert('YOUR HTML CODE GOES INTO HERE');
    $body = new Body($text, 'give-some-unique-id');
    $body->setFormat('markdown');
    $document->addComponent($body);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 2014-09-20
      • 2016-10-10
      相关资源
      最近更新 更多