<commit_before><?php defined('SYSPATH') OR die('No direct access allowed.');

/**
 * River Channel Settings Controller
 *
 * PHP version 5
 * LICENSE: This source file is subject to GPLv3 license 
 * that is available through the world-wide-web at the following URI:
 * http://www.gnu.org/copyleft/gpl.html
 * @author	   <NAME> <<EMAIL>> 
 * @package	   SwiftRiver - http://github.com/ushahidi/Swiftriver_v2
 * @subpackage Controllers
 * @copyright  Ushahidi - http://www.ushahidi.com
 * @license	   http://www.gnu.org/copyleft/gpl.html GNU General Public License v3 (GPLv3) 
 */
class Controller_River_Channels extends Controller_River_Settings {
	
	/**
	 * @return	void
	 */
	public function action_index()
	{
		$this->template->header->title = $this->river->river_name.' ~ '.__('Channel Settings');
		
		$this->active = 'channels';
		$this->settings_content = View::factory('pages/river/settings/channels');		
		$this->settings_content->channels_config = json_encode(Swiftriver_Plugins::channels());
		$this->settings_content->channels = json_encode($this->river->get_channels(TRUE));
		$this->settings_content->base_url = $this->river->get_base_url().'/settings/channels';
	}
	
	/**
	  * Channels restful api
	  */
	public function action_manage()
	{
		$this->template = "";
		$this->auto_render = FALSE;

		switch ($this->request->method())
		{
			case "POST":			
				$channel_array = json_decode($this->request->body(), TRUE);
				
				$channel_config = Swiftriver_Plugins::get_channel_config($channel_array['channel']);			
				if ( ! $channel_config)
					throw new HTTP_Exception_400();
					
				$channel_orm = $this->river->get_channel($channel_array['channel']);
				
				// Make sure the channel is enabled for the case where a disabled
				// channel is being re-added.
				if ( ! (bool) $channel_orm->filter_enabled)
				{
					$channel_orm->filter_enabled = TRUE;
					$channel_orm->save();
				}
				
				echo json_encode(array(
					'id' => $channel_orm->id,
					'channel' => $channel_orm->channel,
					'name' => $channel_config['name'],
					'enabled' => (bool) $channel_orm->filter_enabled,
					'options' => $this->river->get_channel_options($channel_orm)
				));
			break;
			case "PUT":
				$channel_array = json_decode($this->request->body(), TRUE);
				$channel_orm = $this->river->get_channel($channel_array['channel']);
				$channel_orm->filter_enabled = $channel_array['enabled'];
				$channel_orm->save();
			break;
			case "DELETE":
				$channel_id = intval($this->request->param('id', 0));
				$channel_orm = $this->river->get_channel_by_id($channel_id);
				
				if ($channel_orm)
				{
					$channel_orm->delete();
				}
			break;
		}
	 }
	
	/**
	  * Channel options restful api
	  */
	public function action_options()
	{
		$this->template = "";
		$this->auto_render = FALSE;

		if ($this->river->is_expired())
		{
			throw new HTTP_Exception_400(__("Your river has already expired and is no longer 
				receiving drops from your channels"));
		}
	
		$channel_id = intval($this->request->param('id', 0));
		$option_id = intval($this->request->param('id2', 0));
				
		$channel = $this->river->get_channel_by_id($channel_id);
		<commit_msg>Improve the 400 status message<commit_after><?php defined('SYSPATH') OR die('No direct access allowed.');

/**
 * River Channel Settings Controller
 *
 * PHP version 5
 * LICENSE: This source file is subject to GPLv3 license 
 * that is available through the world-wide-web at the following URI:
 * http://www.gnu.org/copyleft/gpl.html
 * @author	   <NAME> <<EMAIL>> 
 * @package	   SwiftRiver - http://github.com/ushahidi/Swiftriver_v2
 * @subpackage Controllers
 * @copyright  Ushahidi - http://www.ushahidi.com
 * @license	   http://www.gnu.org/copyleft/gpl.html GNU General Public License v3 (GPLv3) 
 */
class Controller_River_Channels extends Controller_River_Settings {
	
	/**
	 * @return	void
	 */
	public function action_index()
	{
		$this->template->header->title = $this->river->river_name.' ~ '.__('Channel Settings');
		
		$this->active = 'channels';
		$this->settings_content = View::factory('pages/river/settings/channels');		
		$this->settings_content->channels_config = json_encode(Swiftriver_Plugins::channels());
		$this->settings_content->channels = json_encode($this->river->get_channels(TRUE));
		$this->settings_content->base_url = $this->river->get_base_url().'/settings/channels';
	}
	
	/**
	  * Channels restful api
	  */
	public function action_manage()
	{
		$this->template = "";
		$this->auto_render = FALSE;

		switch ($this->request->method())
		{
			case "POST":			
				$channel_array = json_decode($this->request->body(), TRUE);
				
				$channel_config = Swiftriver_Plugins::get_channel_config($channel_array['channel']);			
				if ( ! $channel_config)
					throw new HTTP_Exception_400();
					
				$channel_orm = $this->river->get_channel($channel_array['channel']);
				
				// Make sure the channel is enabled for the case where a disabled
				// channel is being re-added.
				if ( ! (bool) $channel_orm->filter_enabled)
				{
					$channel_orm->filter_enabled = TRUE;
					$channel_orm->save();
				}
				
				echo json_encode(array(
					'id' => $channel_orm->id,
					'channel' => $channel_orm->channel,
					'name' => $channel_config['name'],
					'enabled' => (bool) $channel_orm->filter_enabled,
					'options' => $this->river->get_channel_options($channel_orm)
				));
			break;
			case "PUT":
				$channel_array = json_decode($this->request->body(), TRUE);
				$channel_orm = $this->river->get_channel($channel_array['channel']);
				$channel_orm->filter_enabled = $channel_array['enabled'];
				$channel_orm->save();
			break;
			case "DELETE":
				$channel_id = intval($this->request->param('id', 0));
				$channel_orm = $this->river->get_channel_by_id($channel_id);
				
				if ($channel_orm)
				{
					$channel_orm->delete();
				}
			break;
		}
	 }
	
	/**
	  * Channel options restful api
	  */
	public function action_options()
	{
		$this->template = "";
		$this->auto_render = FALSE;

		if ($this->river->is_expired())
		{
			$this->response->status(400);
			$this->response->headers('Content-Type', 'application/json');
			echo json_encode(array("error" => __("Oops! Your river has already expired.")));

			return;
		}
	
		$channel_id = intval($this->request->param('id', 0));
		$option_id = intval($this->request->param('id2', 0));
				
		$channel = $this->river->get_channel_by_id($channel_id);
		
{'fraction_non_alphanumeric': 0.16487789702908695, 'fraction_numerical': 0.005132991133924405, 'mean_word_length': 3.74188790560472, 'pattern_counts': {'":': 6, '<': 11, '<?xml version=': 0, '>': 132, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '128393', 'n_tokens_mistral': 2458, 'n_tokens_neox': 2047, 'n_words': 390}