<commit_before><?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */
namespace BNETDocs\Templates\News;
use \BNETDocs\Libraries\Comment;
use \BNETDocs\Libraries\NewsPost;
use \BNETDocs\Libraries\User;
use \CarlBennett\MVC\Libraries\Common;
use \CarlBennett\MVC\Libraries\Pair;
$comments = $this->getContext()->comments;
$object = $this->getContext()->news_post;
$object_id = $this->getContext()->news_post_id;
$active_user = $this->getContext()->active_user;
$title = ($object ? $object->getTitle() : 'News Post Not Found');
$description = filter_var(($object ? $object->getContent(true) : 'The requested news post does not exist or could not be found.'), FILTER_SANITIZE_STRING);
$this->opengraph->attach(new Pair('type', 'article'));
$url = Common::relativeUrlToAbsolute('/news/' . urlencode($object_id));

if ($object)
{
  $created_dt = $object->getCreatedDateTime();
  $draft = !$object->isPublished();
  $edited_dt = $object->getEditedDateTime();
  $url = $object->getURI();
  $user = $object->getUser();
  $user_avatar = $user->getAvatarURI(40);
  $user_id = $object->getUserId();
  $user_name = $user->getName();
  $user_url = $user->getURI();

  $this->opengraph->attach(new Pair('image', '/a/news_categories/' . $object->getCategory()->getFilename()));
  $this->opengraph->attach(new Pair('article:published_time', $created_dt->format('c')));
  if (!is_null($object->getEditedDateTime())) {
    $this->opengraph->attach(new Pair('article:modified_time', $edited_dt->format('c')));
  }
  $this->opengraph->attach(new Pair('article:author:username', $user_name));
  $this->opengraph->attach(new Pair('article:section', $object->getCategory()->getLabel()));

}

$this->opengraph->attach(new Pair('url', $url));

$edit_url       = Common::relativeUrlToAbsolute('/news/edit?id=' . urlencode($object_id));
$delete_url     = Common::relativeUrlToAbsolute('/news/delete?id=' . urlencode($object_id));
$edit_visible   = ($active_user && $active_user->getOption(User::OPTION_ACL_NEWS_MODIFY));
$delete_visible = ($active_user && $active_user->getOption(User::OPTION_ACL_NEWS_DELETE));

require_once('./MarkdownBootstrapFix.inc.php');
require('./header.inc.phtml'); ?>
<div class="container">
<? if ($object) { ?>
<? if ($draft) { ?>
  <div class="alert alert-warning">This news post is marked as <strong>draft</strong>. Edit the news post to <strong>publish</strong> it.</div>
<? } ?>
  <div class="row"><div class="col">
    <span class="float-right">
<?    if ($edit_visible) { ?>
      <a class="btn btn-sm btn-secondary" href="<?=$edit_url?>" title="Edit">📝</a>
<?    } if ($delete_visible) { ?>
      <a class="btn btn-sm btn-danger" href="<?=$delete_url?>" title="Delete">❌</a>
<?    } ?>
      <a class="btn btn-sm btn-primary" href="https://facebook.com/sharer/sharer.php?u=<?=urlencode($url)?>" rel="external" data-popup="1"><img class="img-fluid" src="<?=Common::relativeUrlToAbsolute('/a/social-facebook-24px.png')?>"/></a>
      <a class="btn btn-sm btn-primary" href="https://twitter.com/share?text=<?=urlencode($title)?>&amp;url=<?=urlencode($url)?>" rel="external" data-popup="1"><img class="img-fluid" src="<?=Common::relativeUrlToAbsolute('/a/social-twitter-24px.png')?>"/></a>
    </span>
    <h1><a href="<?=$url?>"><?=filter_var($title, FILTER_SANITIZE_STRING)?></a></h1>
<?  if (!($object->getOptionsBitmask() & NewsPost::OPTION_PUBLISHED)) { ?>
    <section class="red"><p><strong>Warning:</strong> This news post is not yet published. You can view this because you are allowed to create, modify, or delete news posts.</p></section>
<?  } ?>
    <div style="background-color:rgba(0,0,0,0.45);" class="font-weight-bold float-left mb-2 mr-2 p-2 rounded small shadow text-center"><img alt="<?=$object->getCategory()->getLabel()?>" title="<?=$object->getCategory()->getLabel()?>" src="<?=Common::relativeUrlToAbsolute('/a/news_categories/' . $object->getCategory()->getFilename())?>"/><br/><?=$object->getCategory()->getLabel()?></div><?=$object->getContent(true)?>
  </div></div>
  <div class="row"><div class="col">
    <div class="card"><div class="card-body">
      <span class="float-right text-muted">
        <time datetime="<?=$created_dt->format('c')?>"><?=$created_dt->format('l, F j, Y')?></time>
<? if ($edited_dt) { ?>
        | <strong>Edited:</strong> <time datetime="<?=$edited_dt->format('c')?>"><?=$edited_dt->format('l, F j, Y'); ?></time>
<? } ?>
      </span>
<?  echo ($user ?
      sprintf('<a href="%s"><img class="img-fluid rounded mr-2" src="%s"/>%s</a>',
        $user->getURI(), $user->getAvatarURI(40), filter_var($user->getName(), FILTER_SANITIZE_FULL_SPECIAL_CHARS)
      ) : 'Anonymous'
    ); ?>
    </div></div>
  </div></div>
</div>
<div class="container">
<?

$comment_parent_type = Comment::PARENT_TYPE_NEWS_POST; $comment_parent_id = $object_id;
require("./Comment/Section.inc.phtml");

} else { ?>
  <header class="red"><? echo filter_var($title, FILTER_SANITIZE_STRING); ?></header>
  <section class="red"><? echo filter_var($description, FILTER_SANITIZE_STRING); ?></section>
<? } ?>
</div>
<? require("./footer.inc.phtml"); ?><commit_msg>Refactor news post not found layout<commit_after><?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */
namespace BNETDocs\Templates\News;
use \BNETDocs\Libraries\Comment;
use \BNETDocs\Libraries\NewsPost;
use \BNETDocs\Libraries\User;
use \CarlBennett\MVC\Libraries\Common;
use \CarlBennett\MVC\Libraries\Pair;
$comments = $this->getContext()->comments;
$object = $this->getContext()->news_post;
$object_id = $this->getContext()->news_post_id;
$active_user = $this->getContext()->active_user;
$title = ($object ? $object->getTitle() : 'News Post Not Found');
$description = filter_var(($object ? $object->getContent(true) : 'The requested news post does not exist or could not be found.'), FILTER_SANITIZE_STRING);
$this->opengraph->attach(new Pair('type', 'article'));
$url = Common::relativeUrlToAbsolute('/news/' . urlencode($object_id));

if ($object)
{
  $created_dt = $object->getCreatedDateTime();
  $draft = !$object->isPublished();
  $edited_dt = $object->getEditedDateTime();
  $url = $object->getURI();
  $user = $object->getUser();
  $user_avatar = $user->getAvatarURI(40);
  $user_id = $object->getUserId();
  $user_name = $user->getName();
  $user_url = $user->getURI();

  $this->opengraph->attach(new Pair('image', '/a/news_categories/' . $object->getCategory()->getFilename()));
  $this->opengraph->attach(new Pair('article:published_time', $created_dt->format('c')));
  if (!is_null($object->getEditedDateTime())) {
    $this->opengraph->attach(new Pair('article:modified_time', $edited_dt->format('c')));
  }
  $this->opengraph->attach(new Pair('article:author:username', $user_name));
  $this->opengraph->attach(new Pair('article:section', $object->getCategory()->getLabel()));

}

$this->opengraph->attach(new Pair('url', $url));

$edit_url       = Common::relativeUrlToAbsolute('/news/edit?id=' . urlencode($object_id));
$delete_url     = Common::relativeUrlToAbsolute('/news/delete?id=' . urlencode($object_id));
$edit_visible   = ($active_user && $active_user->getOption(User::OPTION_ACL_NEWS_MODIFY));
$delete_visible = ($active_user && $active_user->getOption(User::OPTION_ACL_NEWS_DELETE));

require_once('./MarkdownBootstrapFix.inc.php');
require('./header.inc.phtml'); ?>
<div class="container">
<? if ($object) { ?>
<? if ($draft) { ?>
  <div class="alert alert-warning">This news post is marked as <strong>draft</strong>. Edit the news post to <strong>publish</strong> it.</div>
<? } ?>
  <div class="row"><div class="col">
    <span class="float-right">
<?    if ($edit_visible) { ?>
      <a class="btn btn-sm btn-secondary" href="<?=$edit_url?>" title="Edit">📝</a>
<?    } if ($delete_visible) { ?>
      <a class="btn btn-sm btn-danger" href="<?=$delete_url?>" title="Delete">❌</a>
<?    } ?>
      <a class="btn btn-sm btn-primary" href="https://facebook.com/sharer/sharer.php?u=<?=urlencode($url)?>" rel="external" data-popup="1"><img class="img-fluid" src="<?=Common::relativeUrlToAbsolute('/a/social-facebook-24px.png')?>"/></a>
      <a class="btn btn-sm btn-primary" href="https://twitter.com/share?text=<?=urlencode($title)?>&amp;url=<?=urlencode($url)?>" rel="external" data-popup="1"><img class="img-fluid" src="<?=Common::relativeUrlToAbsolute('/a/social-twitter-24px.png')?>"/></a>
    </span>
    <h1><a href="<?=$url?>"><?=filter_var($title, FILTER_SANITIZE_STRING)?></a></h1>
<?  if (!($object->getOptionsBitmask() & NewsPost::OPTION_PUBLISHED)) { ?>
    <section class="red"><p><strong>Warning:</strong> This news post is not yet published. You can view this because you are allowed to create, modify, or delete news posts.</p></section>
<?  } ?>
    <div style="background-color:rgba(0,0,0,0.45);" class="font-weight-bold float-left mb-2 mr-2 p-2 rounded small shadow text-center"><img alt="<?=$object->getCategory()->getLabel()?>" title="<?=$object->getCategory()->getLabel()?>" src="<?=Common::relativeUrlToAbsolute('/a/news_categories/' . $object->getCategory()->getFilename())?>"/><br/><?=$object->getCategory()->getLabel()?></div><?=$object->getContent(true)?>
  </div></div>
  <div class="row"><div class="col">
    <div class="card"><div class="card-body">
      <span class="float-right text-muted">
        <time datetime="<?=$created_dt->format('c')?>"><?=$created_dt->format('l, F j, Y')?></time>
<? if ($edited_dt) { ?>
        | <strong>Edited:</strong> <time datetime="<?=$edited_dt->format('c')?>"><?=$edited_dt->format('l, F j, Y'); ?></time>
<? } ?>
      </span>
<?  echo ($user ?
      sprintf('<a href="%s"><img class="img-fluid rounded mr-2" src="%s"/>%s</a>',
        $user->getURI(), $user->getAvatarURI(40), filter_var($user->getName(), FILTER_SANITIZE_FULL_SPECIAL_CHARS)
      ) : 'Anonymous'
    ); ?>
    </div></div>
  </div></div>
</div>
<div class="container">
<?

$comment_parent_type = Comment::PARENT_TYPE_NEWS_POST; $comment_parent_id = $object_id;
require("./Comment/Section.inc.phtml");

} else { ?>
  <h1 class="text-danger"><?=filter_var($title, FILTER_SANITIZE_STRING)?></h1>
  <div class="alert alert-danger"><?=filter_var($description, FILTER_SANITIZE_STRING)?></div></div>
<? } ?>
</div>
<? require("./footer.inc.phtml"); ?>
{'fraction_non_alphanumeric': 0.23121780542326756, 'fraction_numerical': 0.005053941102147925, 'mean_word_length': 5.796565389696169, 'pattern_counts': {'":': 0, '<': 200, '<?xml version=': 0, '>': 318, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1337351', 'n_tokens_mistral': 3556, 'n_tokens_neox': 3555, 'n_words': 566}