<?php

  $latestNew = $this->feed['news'][0];


  # Format pubDate: Month day Year
  $latestNew['pubDate'] = date_create($latestNew['pubDate']);
  $latestNew['pubDate'] = $latestNew['pubDate']->format('M j Y');

  # Add th for day
  $latestNew['pubDate'] = explode(' ', $latestNew['pubDate']);
  $latestNew['pubDate'][1] = "{$latestNew['pubDate'][1]}th";
  $latestNew['pubDate'] = join(' ', $latestNew['pubDate']);

  // Remove the isolated "p" tag that contains an anchor tag with text "Source" from description.
  $latestNew['description'] = preg_replace('/<p>\s*<a[^>]*>\s*Source\s*<\/a>\s*<\/p>/i', '', $latestNew['description']);
?>

<div id="cjt-statcs-metabox-news">
	<span class="cjt_dw_latestnewstitle"><span class="cjt-pub-date"><?php echo $latestNew['pubDate'] ?></span>,&nbsp;&nbsp;<a target="_blank" href="https://wpsnippets.ai/pricing?utm_source=cjt_free_user&utm_medium=dashboard_header&utm_campaign=click_for_premium_button"><?php echo $latestNew['title'] ?></a></span>
	<p class="cjt_dw_description"><?php echo $latestNew['description'] ?></p>
</div>
<hr />
<div>
	<table id="cjt-statcs-metabox">
		<thead>
			<tr>
				<th colspan="2"><strong><?php echo cssJSToolbox::getText('Total') ?></strong></th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td><?php echo cssJSToolbox::getText('Code Blocks') ?></td>
				<td><strong><?php echo $this->activeBlocks ?></strong></td>
			</tr>
			<tr>
				<td><?php echo cssJSToolbox::getText('Metabox Code Blocks') ?></td>
				<td><strong><?php echo $this->activeMetaboxBlocks ?></strong></td>
			</tr>
			<tr>
				<td><?php echo cssJSToolbox::getText('Code Blocks') ?>&nbsp;<span class="cjt-grayed"><?php echo cssJSToolbox::getText('Inactive') ?></span></td>
				<td><strong><?php echo $this->inactiveBlocks ?></strong></td>
			</tr>
			<tr>
				<td><?php echo cssJSToolbox::getText('Metabox Code Blocks') ?>&nbsp;<span class="cjt-grayed"><?php echo cssJSToolbox::getText('Inactive') ?></span></td>
				<td><strong><?php echo $this->inactiveMetaboxBlocks ?></strong></td>
			</tr>
            <tr>
                <td><?php echo cssJSToolbox::getText('Code Files') ?></td>
                <td><strong><?php echo $this->codeFiles ?></strong></td>
            </tr>
			<tr>
				<td><?php echo cssJSToolbox::getText('Code Templates') ?></td>
				<td><strong><?php echo $this->templates ?></strong></td>
			</tr>
		</tbody>
	</table>
</div>
<hr />
<div id="cjt-statcs-metabox-info">
    <div class="cjt-stat-metabox-version">
		<span><?php echo cssJSToolbox::getText('CJT Version') ?>:&nbsp;&nbsp;<?php echo CJTPlugin::VERSION; ?>
		<?php if ( class_exists( 'CJTPlusPluginInterface' ) ) {
			$reflector = new \ReflectionClass( 'CJTPlus' );
			$CJTPlusVersion = get_plugin_data( str_replace( 'plus.class', 'plus', $reflector->getFileName() ) )['Version'];
			echo ' / ' . cssJSToolbox::getText('CJT PLUS Version') ?>:&nbsp;&nbsp;<?php echo $CJTPlusVersion;
		} ?>
		</span>
    </div>
</div>