<commit_before><?php

/**
 * CRUD action of blog entries.
 *
 * @link http://github.com/marcoraddatz/candyCMS
 * @author <NAME> <http://marcoraddatz.com>
 * @license MIT
 * @since 1.0
 *
 */

namespace candyCMS\Core\Controllers;

use candyCMS\Core\Helpers\Helper;
use candyCMS\Core\Helpers\I18n;

class Blogs extends Main {

  /**
   * Show blog entry or blog overview (depends on a given ID or not).
   *
   * @access protected
   * @return string HTML content
   *
   */
  protected function _show() {
    $sTemplateDir  = Helper::getTemplateDir($this->_sController, 'show');
    $sTemplateFile = Helper::getTemplateType($sTemplateDir, 'show');
    $this->oSmarty->setTemplateDir($sTemplateDir);

    if ($this->_iId) {
      $this->_aData = $this->_oModel->getId($this->_iId);

      if (!$this->_aData[1]['id'])
        return Helper::redirectTo('/errors/404');

      # If comments are disabled
      if (!DISABLE_COMMENTS) {
        $sClass     = $this->__autoload('Comments');
        $oComments  = new $sClass($this->_aRequest, $this->_aSession);

        $oComments->__init();
        $oComments->_setParentData($this->_aData);

        $this->oSmarty->assign('_comments_', $oComments->show());
      }

      $this->oSmarty->assign('blogs', $this->_aData);

      # Bugfix: This is necessary, because comments also do a setDir on the singleton object.
      $this->oSmarty->setTemplateDir($sTemplateDir);
    }

    else {
      # Get tags
      if (!$this->oSmarty->isCached($sTemplateFile, UNIQUE_ID)) {
        $this->_aData = isset($this->_aRequest['search']) && $this->_aRequest['search'] ?
                $this->_oModel->getOverviewByTag() :
                $this->_oModel->getOverview();

        # Limit to maximum pages
        if (isset($this->_aRequest['page']) && (int) $this->_aRequest['page'] > $this->_oModel->oPagination->getPages())
          return Helper::redirectTo('/errors/404');

        else {
          $this->oSmarty->assign('blogs', $this->_aData);
          $this->oSmarty->assign('_pagination_', $this->_oModel->oPagination->showSurrounding());
        }
      }
    }

    $this->setDescription($this->_setBlogsDescription());
    $this->setKeywords($this->_setBlogsKeywords());
    $this->setTitle($this->_setBlogsTitle());

    return $this->oSmarty->fetch($sTemplateFile, UNIQUE_ID);
  }

  /**
   * Show blog as RSS.
   *
   * @access protected
   * @return string XML
   *
   */
  protected function _overviewRSS() {
    $sTemplateDir  = Helper::getTemplateDir($this->_sController, 'overviewRSS');
    $sTemplateFile = Helper::getTemplateType($sTemplateDir, 'overviewRSS');
    $this->oSmarty->setTemplateDir($sTemplateDir);

    if (!$this->oSmarty->isCached($sTemplateFile, UNIQUE_ID)) {
      $this->_aData = isset($this->_aRequest['search']) && $this->_aRequest['search'] ?
          $this->_oModel->getOverviewByTag() :
          $this->_oModel->getOverview();

      $this->oSmarty->assign('data', $this->_aData);
      $this->oSmarty->assign('_WEBSITE', array(
          'title' => $this->_setBlogsTitle(),
          'date'  => date('D, d M Y H:i:s O', time())
      ));
    }

    header('Content-Type: application/rss+xml');
    return $this->oSmarty->fetch($sTemplateFile, UNIQUE_ID);
  }

  /**
   * Return the blog meta description and remove highlighted text if needed.
   *
   * @access private
   * @return string meta description
   *
   */
  private function _setBlogsDescription() {
    if (isset($this->_aRequest['page']) && $this->_aRequest['page'] > 1)
      return I18n::get('global.blogs') . ' - ' . I18n::get('global.page') . ' ' . (int) $this->_aRequest['page'];

    elseif ($this->_iId) {
      if (isset($this->_aData[1]['teaser']) && $this->_aData[1]['teaser'])
        return $this->_removeHighlight($this->_aData[1]['teaser']);<commit_msg>added title to blogs rss<commit_after><?php

/**
 * CRUD action of blog entries.
 *
 * @link http://github.com/marcoraddatz/candyCMS
 * @author <NAME> <http://marcoraddatz.com>
 * @license MIT
 * @since 1.0
 *
 */

namespace candyCMS\Core\Controllers;

use candyCMS\Core\Helpers\Helper;
use candyCMS\Core\Helpers\I18n;

class Blogs extends Main {

  /**
   * Show blog entry or blog overview (depends on a given ID or not).
   *
   * @access protected
   * @return string HTML content
   *
   */
  protected function _show() {
    $sTemplateDir  = Helper::getTemplateDir($this->_sController, 'show');
    $sTemplateFile = Helper::getTemplateType($sTemplateDir, 'show');
    $this->oSmarty->setTemplateDir($sTemplateDir);

    if ($this->_iId) {
      $this->_aData = $this->_oModel->getId($this->_iId);

      if (!$this->_aData[1]['id'])
        return Helper::redirectTo('/errors/404');

      # If comments are disabled
      if (!DISABLE_COMMENTS) {
        $sClass     = $this->__autoload('Comments');
        $oComments  = new $sClass($this->_aRequest, $this->_aSession);

        $oComments->__init();
        $oComments->_setParentData($this->_aData);

        $this->oSmarty->assign('_comments_', $oComments->show());
      }

      $this->oSmarty->assign('blogs', $this->_aData);

      # Bugfix: This is necessary, because comments also do a setDir on the singleton object.
      $this->oSmarty->setTemplateDir($sTemplateDir);
    }

    else {
      # Get tags
      if (!$this->oSmarty->isCached($sTemplateFile, UNIQUE_ID)) {
        $this->_aData = isset($this->_aRequest['search']) && $this->_aRequest['search'] ?
                $this->_oModel->getOverviewByTag() :
                $this->_oModel->getOverview();

        # Limit to maximum pages
        if (isset($this->_aRequest['page']) && (int) $this->_aRequest['page'] > $this->_oModel->oPagination->getPages())
          return Helper::redirectTo('/errors/404');

        else {
          $this->oSmarty->assign('blogs', $this->_aData);
          $this->oSmarty->assign('_pagination_', $this->_oModel->oPagination->showSurrounding());
        }
      }
    }

    $this->setDescription($this->_setBlogsDescription());
    $this->setKeywords($this->_setBlogsKeywords());
    $this->setTitle($this->_setBlogsTitle());

    return $this->oSmarty->fetch($sTemplateFile, UNIQUE_ID);
  }

  /**
   * Show blog as RSS.
   *
   * @access protected
   * @return string XML
   *
   */
  protected function _overviewRSS() {
    $sTemplateDir  = Helper::getTemplateDir($this->_sController, 'overviewRSS');
    $sTemplateFile = Helper::getTemplateType($sTemplateDir, 'overviewRSS');
    $this->oSmarty->setTemplateDir($sTemplateDir);

    if (!$this->oSmarty->isCached($sTemplateFile, UNIQUE_ID)) {
      $this->_aData = isset($this->_aRequest['search']) && $this->_aRequest['search'] ?
          $this->_oModel->getOverviewByTag() :
          $this->_oModel->getOverview();

      $this->oSmarty->assign('data', $this->_aData);
      $this->oSmarty->assign('_WEBSITE', array(
          'title' => $this->_setBlogsTitle(),
          'date'  => date('D, d M Y H:i:s O', time())
      ));
    }

    $this->setTitle($this->_setBlogsTitle());

    header('Content-Type: application/rss+xml');
    return $this->oSmarty->fetch($sTemplateFile, UNIQUE_ID);
  }

  /**
   * Return the blog meta description and remove highlighted text if needed.
   *
   * @access private
   * @return string meta description
   *
   */
  private function _setBlogsDescription() {
    if (isset($this->_aRequest['page']) && $this->_aRequest['page'] > 1)
      return I18n::get('global.blogs') . ' - ' . I18n::get('global.page') . ' ' . (int) $this->_aRequest['page'];

    elseif ($this->_iId) {
      if (isset($this->_aData[1]['teaser']) && $this->_aData[1]['teaser'])
        return $this->_removeHighlight($this->_aData[1]['teaser']);
{'fraction_non_alphanumeric': 0.182444733420026, 'fraction_numerical': 0.00494148244473342, 'mean_word_length': 3.2096332785987958, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 179, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6416225', 'n_tokens_mistral': 2588, 'n_tokens_neox': 2484, 'n_words': 424}