<commit_before><?php
/**
 * Media Shell File
 *
 * Copyright (c) 2007-2009 <NAME>
 *
 * Distributed under the terms of the MIT License.
 * Redistributions of files must retain the above copyright notice.
 *
 * PHP version 5
 * CakePHP version 1.2
 *
 * @package    media
 * @subpackage media.shells
 * @copyright  2007-2009 <NAME> <<EMAIL>>
 * @license    http://www.opensource.org/licenses/mit-license.php The MIT License
 * @link       http://github.com/davidpersson/media
 */
App::import('Core', array('ConnectionManager', 'Folder'));
require_once(APP . 'plugins' . DS . 'media'. DS . 'config' . DS . 'core.php');
Configure::write('Cache.disable', true);
/**
 * Media Shell Class
 *
 * @package    media
 * @subpackage media.shells
 */
class MediaShell extends Shell {
	var $tasks = array('Sync', 'Make', 'Collect');
	var $verbose = false;
	var $quiet = false;
/**
 * Width of shell in number of characters per line
 *
 * @var integer
 */
	var $width = 80;
/**
 * startup
 *
 * @access public
 * @return void
 */
	function startup() {
		$this->verbose = isset($this->params['verbose']);
		$this->quiet = isset($this->params['quiet']);
		parent::startup();
	}
/**
 * _welcome
 *
 * @access protected
 * @return void
 */
	function _welcome() {
		$this->clear();
		$this->hr();
		$this->out('Media Shell');
		$this->hr();
	}
/**
 * main
 *
 * @access public
 * @return void
 */
	function main() {
		$this->out('[I]nitialize Media Directory');
		$this->out('[P]rotect Transfer Directory');
		$this->out('[S]ynchronize');
		$this->out('[M]ake');
		$this->out('[C]ollect');
		$this->out('[H]elp');
		$this->out('[Q]uit');

		$action = strtoupper($this->in(__('What would you like to do?', true),
										array('I', 'P', 'S', 'M', 'C', 'H', 'Q'),'q'));

		$this->out();

		switch ($action) {
			case 'I':
				$this->init();
			case 'P':
				$this->protect();
				break;
			case 'S':
				$this->Sync->execute();
				break;
			case 'M':
				$this->Make->execute();
				break;
			case 'C':
				$this->Collect->execute();
				break;
			case 'H':
				$this->help();
				break;
			case 'Q':
				$this->_stop();
		}
		$this->main();
	}
/**
 * Initializes directory structure
 *
 * @access public
 * @return void
 */
	function init() {
		$message = 'Do you want to create missing media directories now?';

		if ($this->in($message, 'y,n', 'n') == 'n') {
			return false;
		}

		$dirs = array(
			MEDIA => array(),
			MEDIA_STATIC => Medium::short(),
			MEDIA_TRANSFER => Medium::short(),
			MEDIA_FILTER => Medium::short(),
			);

		foreach ($dirs as $dir => $subDirs) {
			if (is_dir($dir)) {
				$result = 'SKIP';
			} else {
				new Folder($dir, true);

				if (is_dir($dir)) {
					$result = 'OK';
				} else {
					$result = 'FAIL';
				}
			}
			$this->out(sprintf('%-50s [%-4s]', $this->shortPath($dir), $result));

			foreach ($subDirs as $subDir) {
				if (is_dir($dir . $subDir)) {
					$result = 'SKIP';
				} else {
					new Folder($dir . $subDir, true);

					if (is_dir($dir . $subDir)) {
						$result = 'OK';
					} else {
						$result = 'FAIL';
					}
				}
				$this->out(sprintf('%-50s [%-4s]', $this->shortPath($dir . $subDir), $result));
			}
		}

		$this->out();
		$this->out('Please remember to set the correct permission on e.g. the transfer directory.');
		$this->out();
		return true;
	}
/**
 * Protects the transfer directory
 *
 * @access public
 * @return void
 */
	function protect() {
		$file = MEDIA_TRANSFERS . '.htaccess';

		if (is_file($file)) {
			$this->err($this->shortPath($file) . ' is already present.');
			return true;
		}
		$this->out('Your transfer directory is missing a htaccess file to block requests.');

		if ($this->in('Do you want to create it now?', 'y,n', 'n') == 'n') {
			return false;
		}

		$File = new File($file);
		$File->append("Order deny,allow\n");
		$File->append("Deny from all\n");
		$File->close();

		$this->out($this->shortPath($File->pwd()) . 'created.');
		$this->out();
		return true;
	}
/**
 * Displays help contents
 *
 * @access public
 */
	function help() {
		// 63 chars ===============================================================
		$this->out("NAME");
		$this->out("\tmedia -- the 23rd shell");
		$this->out();
		$this->out("SYNOPSIS");
		$this->out("\tcake media <params> <command> <args>");
		$this->out();
		$this->out("COMMANDS");
		$this->out("\tinit");
		$this->out("\t\tInitializes the media directory structure.");
		$this->out();
		$this->out("\tprotect");<commit_msg>Fixing typo and call to protect method<commit_after><?php
/**
 * Media Shell File
 *
 * Copyright (c) 2007-2009 <NAME>
 *
 * Distributed under the terms of the MIT License.
 * Redistributions of files must retain the above copyright notice.
 *
 * PHP version 5
 * CakePHP version 1.2
 *
 * @package    media
 * @subpackage media.shells
 * @copyright  2007-2009 <NAME> <<EMAIL>>
 * @license    http://www.opensource.org/licenses/mit-license.php The MIT License
 * @link       http://github.com/davidpersson/media
 */
App::import('Core', array('ConnectionManager', 'Folder'));
require_once(APP . 'plugins' . DS . 'media'. DS . 'config' . DS . 'core.php');
Configure::write('Cache.disable', true);
/**
 * Media Shell Class
 *
 * @package    media
 * @subpackage media.shells
 */
class MediaShell extends Shell {
	var $tasks = array('Sync', 'Make', 'Collect');
	var $verbose = false;
	var $quiet = false;
/**
 * Width of shell in number of characters per line
 *
 * @var integer
 */
	var $width = 80;
/**
 * startup
 *
 * @access public
 * @return void
 */
	function startup() {
		$this->verbose = isset($this->params['verbose']);
		$this->quiet = isset($this->params['quiet']);
		parent::startup();
	}
/**
 * _welcome
 *
 * @access protected
 * @return void
 */
	function _welcome() {
		$this->clear();
		$this->hr();
		$this->out('Media Shell');
		$this->hr();
	}
/**
 * main
 *
 * @access public
 * @return void
 */
	function main() {
		$this->out('[I]nitialize Media Directory');
		$this->out('[P]rotect Transfer Directory');
		$this->out('[S]ynchronize');
		$this->out('[M]ake');
		$this->out('[C]ollect');
		$this->out('[H]elp');
		$this->out('[Q]uit');

		$action = strtoupper($this->in(__('What would you like to do?', true),
										array('I', 'P', 'S', 'M', 'C', 'H', 'Q'),'q'));

		$this->out();

		switch ($action) {
			case 'I':
				$this->init();
				break;
			case 'P':
				$this->protect();
				break;
			case 'S':
				$this->Sync->execute();
				break;
			case 'M':
				$this->Make->execute();
				break;
			case 'C':
				$this->Collect->execute();
				break;
			case 'H':
				$this->help();
				break;
			case 'Q':
				$this->_stop();
		}
		$this->main();
	}
/**
 * Initializes directory structure
 *
 * @access public
 * @return void
 */
	function init() {
		$message = 'Do you want to create missing media directories now?';

		if ($this->in($message, 'y,n', 'n') == 'n') {
			return false;
		}

		$dirs = array(
			MEDIA => array(),
			MEDIA_STATIC => Medium::short(),
			MEDIA_TRANSFER => Medium::short(),
			MEDIA_FILTER => Medium::short(),
			);

		foreach ($dirs as $dir => $subDirs) {
			if (is_dir($dir)) {
				$result = 'SKIP';
			} else {
				new Folder($dir, true);

				if (is_dir($dir)) {
					$result = 'OK';
				} else {
					$result = 'FAIL';
				}
			}
			$this->out(sprintf('%-50s [%-4s]', $this->shortPath($dir), $result));

			foreach ($subDirs as $subDir) {
				if (is_dir($dir . $subDir)) {
					$result = 'SKIP';
				} else {
					new Folder($dir . $subDir, true);

					if (is_dir($dir . $subDir)) {
						$result = 'OK';
					} else {
						$result = 'FAIL';
					}
				}
				$this->out(sprintf('%-50s [%-4s]', $this->shortPath($dir . $subDir), $result));
			}
		}

		$this->out();
		$this->protect();
		$this->out('Remember to set the correct permissions on transfer and filter directory.');
	}
/**
 * Protects the transfer directory
 *
 * @access public
 * @return void
 */
	function protect() {
		$file = MEDIA_TRANSFER . '.htaccess';

		if (is_file($file)) {
			$this->err($this->shortPath($file) . ' is already present.');
			return true;
		}
		$this->out('Your transfer directory is missing a htaccess file to block requests.');

		if ($this->in('Do you want to create it now?', 'y,n', 'n') == 'n') {
			return false;
		}

		$File = new File($file);
		$File->append("Order deny,allow\n");
		$File->append("Deny from all\n");
		$File->close();

		$this->out($this->shortPath($File->pwd()) . ' created.');
		$this->out();
		return true;
	}
/**
 * Displays help contents
 *
 * @access public
 */
	function help() {
		// 63 chars ===============================================================
		$this->out("NAME");
		$this->out("\tmedia -- the 23rd shell");
		$this->out();
		$this->out("SYNOPSIS");
		$this->out("\tcake media <params> <command> <args>");
		$this->out();
		$this->out("COMMANDS");
		$this->out("\tinit");
		$this->out("\t\tInitializes the media directory structure.");
		$this->out();
		$this->out("\tprotect");
{'fraction_non_alphanumeric': 0.22677871148459383, 'fraction_numerical': 0.006946778711484594, 'mean_word_length': 3.1632462686567164, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 143, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4520351', 'n_tokens_mistral': 3641, 'n_tokens_neox': 3115, 'n_words': 753}