<commit_before><?php
/**
  * @package Module
  * @subpackage News
  */

/**
  * @package Module
  * @subpackage News
  */
class NewsWebModule extends WebModule {
  protected $id = 'news';
  protected $feeds = array();
  protected $defaultController = 'RSSDataController';
  protected $feedIndex = 0;
  protected $feed;
  protected $maxPerPage = 10;
  protected $maxPerPane = 5;
  protected $showImages = true;
  protected $showPubDate = false;
  protected $showAuthor = false;
  protected $showLink = false;
  
  public static function validateFeed($section, $feedData) {
        if (!self::argVal($feedData, 'TITLE')) {
            return new KurogoError(1, $this->getLocalizedString('ERROR_NO_TITLE'),$this->getLocalizedString('ERROR_NO_TITLE_DESCRIPTION'));
        }

        if (!isset($feedData['CONTROLLER_CLASS'])) {
            $feedData['CONTROLLER_CLASS'] = $this->defaultController;
        }
        
        try {
            $controller = DataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
        } catch (KurogoConfigurationException $e) {
            return KurogoError::errorFromException($e);
        }
        
        return true;
  }

  protected function feedURLForFeed($feedIndex) {
    return isset($this->feeds[$feedIndex]) ? 
      $this->feeds[$feedIndex]['baseURL'] : null;
  }
  
  protected function getImageForStory($story) {
    if ($this->showImages) {
        $image = $story->getImage();
        
        if ($image) {
          return array(
            'src'    => $image->getURL(),
            'width'  => $image->getProperty('width'),
            'height' => $image->getProperty('height'),
          );
        }
    }
    
    return null;
  }

  protected function urlForPage($pageNumber) {
    $args = $this->args;
    $args['storyPage'] = $pageNumber;
    return $this->buildBreadcrumbURL('story', $args, false);
  }

  protected function feedURL($feedIndex, $addBreadcrumb=true) {
    return $this->buildBreadcrumbURL('index', array(
      'section' => $feedIndex
    ), $addBreadcrumb);
  }

    protected function cleanContent($content) {
    
        //deal with pre tags. strip out pre tags and add <br> for newlines
        $bits = preg_split( '#(<pre.*?'.'>)(.*?)(</pre>)#s', $content, -1, PREG_SPLIT_DELIM_CAPTURE);
        $content = array_shift($bits);
        $i=0;
        while ($i<count($bits)) {
            $tag = $bits[$i++];
            $content .= nl2br($bits[$i++]);
            $close = $bits[$i++];
            $i++;
        }
    
        return $content;
    }

  public function getFeeds() {
    return $this->feeds;
  }
  
  public function getFeed($index) {
    if (isset($this->feeds[$index])) {
        $feedData = $this->feeds[$index];
        if (!isset($feedData['CONTROLLER_CLASS'])) {
            $feedData['CONTROLLER_CLASS'] = $this->defaultController;
        }
        $controller = DataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
        return $controller;
    } else {
        throw new KurogoConfigurationException($this->getLocalizedString('ERROR_INVALID_FEED', $index));
    }
  }
    public function searchItems($searchTerms, $limit=null, $data=null) {
    
        $this->feed->addFilter('search', $searchTerms);
        $items = $this->feed->items(0, $limit);
        
        return $items;<commit_msg>make defaultController a class constant so it can be used in static contexts<commit_after><?php
/**
  * @package Module
  * @subpackage News
  */

/**
  * @package Module
  * @subpackage News
  */
class NewsWebModule extends WebModule {
  const defaultController = 'RSSDataController';
  protected $id = 'news';
  protected $feeds = array();
  protected $feedIndex = 0;
  protected $feed;
  protected $maxPerPage = 10;
  protected $maxPerPane = 5;
  protected $showImages = true;
  protected $showPubDate = false;
  protected $showAuthor = false;
  protected $showLink = false;
  
  public static function validateFeed($section, $feedData) {
        if (!self::argVal($feedData, 'TITLE')) {
            return new KurogoError(1, $this->getLocalizedString('ERROR_NO_TITLE'),$this->getLocalizedString('ERROR_NO_TITLE_DESCRIPTION'));
        }

        if (!isset($feedData['CONTROLLER_CLASS'])) {
            $feedData['CONTROLLER_CLASS'] = self::defaultController;
        }
        
        try {
            $controller = DataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
        } catch (KurogoConfigurationException $e) {
            return KurogoError::errorFromException($e);
        }
        
        return true;
  }

  protected function feedURLForFeed($feedIndex) {
    return isset($this->feeds[$feedIndex]) ? 
      $this->feeds[$feedIndex]['baseURL'] : null;
  }
  
  protected function getImageForStory($story) {
    if ($this->showImages) {
        $image = $story->getImage();
        
        if ($image) {
          return array(
            'src'    => $image->getURL(),
            'width'  => $image->getProperty('width'),
            'height' => $image->getProperty('height'),
          );
        }
    }
    
    return null;
  }

  protected function urlForPage($pageNumber) {
    $args = $this->args;
    $args['storyPage'] = $pageNumber;
    return $this->buildBreadcrumbURL('story', $args, false);
  }

  protected function feedURL($feedIndex, $addBreadcrumb=true) {
    return $this->buildBreadcrumbURL('index', array(
      'section' => $feedIndex
    ), $addBreadcrumb);
  }

    protected function cleanContent($content) {
    
        //deal with pre tags. strip out pre tags and add <br> for newlines
        $bits = preg_split( '#(<pre.*?'.'>)(.*?)(</pre>)#s', $content, -1, PREG_SPLIT_DELIM_CAPTURE);
        $content = array_shift($bits);
        $i=0;
        while ($i<count($bits)) {
            $tag = $bits[$i++];
            $content .= nl2br($bits[$i++]);
            $close = $bits[$i++];
            $i++;
        }
    
        return $content;
    }

  public function getFeeds() {
    return $this->feeds;
  }
  
  public function getFeed($index) {
    if (isset($this->feeds[$index])) {
        $feedData = $this->feeds[$index];
        if (!isset($feedData['CONTROLLER_CLASS'])) {
            $feedData['CONTROLLER_CLASS'] = self::defaultController;
        }
        $controller = DataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
        return $controller;
    } else {
        throw new KurogoConfigurationException($this->getLocalizedString('ERROR_INVALID_FEED', $index));
    }
  }
    public function searchItems($searchTerms, $limit=null, $data=null) {
    
        $this->feed->addFilter('search', $searchTerms);
        $items = $this->feed->items(0, $limit);
        
        return $items;
{'fraction_non_alphanumeric': 0.15321620011911852, 'fraction_numerical': 0.0026801667659321023, 'mean_word_length': 2.7090005521811156, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 59, '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': '2744012', 'n_tokens_mistral': 2086, 'n_tokens_neox': 2057, 'n_words': 397}