<commit_before><?php

/**
 * article actions.
 *
 * @package    frostty
 * @subpackage article
 * @author     <NAME>
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class articleActions extends ApplicationActions
{
  /**
   * View for popular articles
   * 
   * @param sfWebRequest $request
   */
  public function executeHot(sfWebRequest $request)
  {
    $this->flavour = $request->getParameter('flavour', 'all');
    
    $q = Doctrine_Query::create()->select('a.*, t.*, v.*')
      ->from('article a, a.Thing t')
      ->groupBy('a.id')
      ->orderBy('t.hot DESC');
    
    if (in_array($this->flavour, Article::getFlavours())){
      $q->where('a.flavour = ?', $this->flavour);
    } else {
      $this->flavour = 'all';
    }
    
    $cache_hash = array(
      'hot',
      'flavour-' . $this->flavour,
      'page-'  . $request->getParameter('page', 1),
      'perpage-' . sfConfig::get('app_things_perpage')  
    );
    
    $cache_hash = implode('_', $cache_hash);
    $q->useResultCache(true, 3600, $cache_hash);
    
    $this->pager = new sfDoctrinePager('Article', sfConfig::get('app_things_perpage'));
    $this->pager->setQuery($q);
    $this->pager->setPage($request->getParameter('page', 1));
    $this->pager->init();
        
    $this->insertCodeFlavouredResources();
    
    // page title
    $title = '';
    if ($this->flavour != 'all'){
      $title .= 'Hot ' . Article::getFlavourName($this->flavour);
      $title .= ' - Page ' . $request->getParameter('page', 1);
      $title .= ' - ' . sfConfig::get('app_name');
    } else {
      $title .= sfConfig::get('app_tagline');
      $title .= ' - Page ' . $request->getParameter('page', 1);
      $title .= ' - ' . sfConfig::get('app_name');
    }
    $this->getResponse()->setTitle($title);
  }

  /**
   * View for latest articles
   * 
   * @param $request
   */
  public function executeLatest(sfWebRequest $request)
  {
    $this->flavour = $request->getParameter('flavour', 'all');
    
    $q = Doctrine_Query::create()->select('a.*, t.*, v.*')
      ->from('article a, a.Thing t')
      ->groupBy('a.id')
      ->orderBy('a.created_at DESC');
    
    if (in_array($this->flavour, Article::getFlavours())){
      $q->where('a.flavour = ?', $this->flavour);
    } else {
      $this->flavour = 'all';
    }
    
    $cache_hash = array(
      'latest',
      'flavour-' . $this->flavour,
      'page-' . $request->getParameter('page', 1),
      'perpage-' . sfConfig::get('app_things_perpage')  
    );
    
    $cache_hash = implode('_', $cache_hash);
    $q->useResultCache(true, 3600, $cache_hash);

    $this->pager = new sfDoctrinePager('Article', sfConfig::get('app_things_perpage'));
    $this->pager->setQuery($q);
    $this->pager->setPage($request->getParameter('page', 1));
    $this->pager->init();
    
    $this->insertCodeFlavouredResources();
    
    // page title
    $title = '';
    if ($this->flavour != 'all'){
      $title .= 'Latest ' . Article::getFlavourName($this->flavour);
      $title .= ' - Page ' . $request->getParameter('page', 1);
      $title .= ' - ' . sfConfig::get('app_name');
    } else {
      $title .= sfConfig::get('app_tagline');
      $title .= ' - Page ' . $request->getParameter('page', 1);
      $title .= ' - ' . sfConfig::get('app_name');
    }
    $this->getResponse()->setTitle($title);
  }
  
  /**
   * Insert syntax highlighter js and related code brushes, if there are code
   * flavoured articles in the pager assigned to the current template
   * 
   */
  private function insertCodeFlavouredResources()<commit_msg>Removed page number from title on first page<commit_after><?php

/**
 * article actions.
 *
 * @package    frostty
 * @subpackage article
 * @author     <NAME>
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class articleActions extends ApplicationActions
{
  /**
   * View for popular articles
   * 
   * @param sfWebRequest $request
   */
  public function executeHot(sfWebRequest $request)
  {
    $this->flavour = $request->getParameter('flavour', 'all');
    
    $q = Doctrine_Query::create()->select('a.*, t.*, v.*')
      ->from('article a, a.Thing t')
      ->groupBy('a.id')
      ->orderBy('t.hot DESC');
    
    if (in_array($this->flavour, Article::getFlavours())){
      $q->where('a.flavour = ?', $this->flavour);
    } else {
      $this->flavour = 'all';
    }
    
    $cache_hash = array(
      'hot',
      'flavour-' . $this->flavour,
      'page-'  . $request->getParameter('page', 1),
      'perpage-' . sfConfig::get('app_things_perpage')  
    );
    
    $cache_hash = implode('_', $cache_hash);
    $q->useResultCache(true, 3600, $cache_hash);
    
    $this->pager = new sfDoctrinePager('Article', sfConfig::get('app_things_perpage'));
    $this->pager->setQuery($q);
    $this->pager->setPage($request->getParameter('page', 1));
    $this->pager->init();
        
    $this->insertCodeFlavouredResources();
    
    // page title
    $title = '';
    if ($this->flavour != 'all'){
      $title .= 'Hot ' . Article::getFlavourName($this->flavour);
      $title .= ' - Page ' . $request->getParameter('page', 1);
      $title .= ' - ' . sfConfig::get('app_name');
    } elseif ($request->getParameter('page', 1) != 1) {
      $title .= sfConfig::get('app_tagline');
      $title .= ' - Page ' . $request->getParameter('page', 1);
      $title .= ' - ' . sfConfig::get('app_name');
    }
    $this->getResponse()->setTitle($title);
  }

  /**
   * View for latest articles
   * 
   * @param $request
   */
  public function executeLatest(sfWebRequest $request)
  {
    $this->flavour = $request->getParameter('flavour', 'all');
    
    $q = Doctrine_Query::create()->select('a.*, t.*, v.*')
      ->from('article a, a.Thing t')
      ->groupBy('a.id')
      ->orderBy('a.created_at DESC');
    
    if (in_array($this->flavour, Article::getFlavours())){
      $q->where('a.flavour = ?', $this->flavour);
    } else {
      $this->flavour = 'all';
    }
    
    $cache_hash = array(
      'latest',
      'flavour-' . $this->flavour,
      'page-' . $request->getParameter('page', 1),
      'perpage-' . sfConfig::get('app_things_perpage')  
    );
    
    $cache_hash = implode('_', $cache_hash);
    $q->useResultCache(true, 3600, $cache_hash);

    $this->pager = new sfDoctrinePager('Article', sfConfig::get('app_things_perpage'));
    $this->pager->setQuery($q);
    $this->pager->setPage($request->getParameter('page', 1));
    $this->pager->init();
    
    $this->insertCodeFlavouredResources();
    
    // page title
    $title = '';
    if ($this->flavour != 'all'){
      $title .= 'Latest ' . Article::getFlavourName($this->flavour);
      $title .= ' - Page ' . $request->getParameter('page', 1);
      $title .= ' - ' . sfConfig::get('app_name');
    } elseif ($request->getParameter('page', 1) != 1) {
      $title .= sfConfig::get('app_tagline');
      $title .= ' - Page ' . $request->getParameter('page', 1);
      $title .= ' - ' . sfConfig::get('app_name');
    }
    $this->getResponse()->setTitle($title);
  }
  
  /**
   * Insert syntax highlighter js and related code brushes, if there are code
   * flavoured articles in the pager assigned to the current template
   * 
   */
  private function insertCodeFlavouredResources()
{'fraction_non_alphanumeric': 0.20030017737754127, 'fraction_numerical': 0.01009687542638832, 'mean_word_length': 2.7939958592132506, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 119, 'https://': 0, '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': '5709188', 'n_tokens_mistral': 2623, 'n_tokens_neox': 2476, 'n_words': 434}