<commit_before><?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Name:			blog_skin_model.php
 *
 * Description:		This model finds and loads blog skins
 *
 **/

/**
 * OVERLOADING NAILS' MODELS
 *
 * Note the name of this class; done like this to allow apps to extend this class.
 * Read full explanation at the bottom of this file.
 *
 **/

class NAILS_Blog_skin_model extends NAILS_Model
{
	protected $_available;
	protected $_skins;
	protected $_skin_locations;


	// --------------------------------------------------------------------------


	/**
	 * Construct the model.
	 */
	public function __construct()
	{
		parent::__construct();

		// --------------------------------------------------------------------------

		$this->_available = NULL;

		/**
		 * Skin locations
		 * The model will search these directories for skins; to add more directories extend this
		 * This must be an array with 2 indexes:
		 * `path`	=> The absolute path to the directory containing the skins (required)
		 * `url`	=> The URL to access the skin (required)
		 * `regex`	=> If the directory doesn't only contain skin then specify a regex to filter by
		 */

		if ( empty( $this->_skin_locations ) ) :

			$this->_skin_locations = array();

		endif;

		//	'Official' skins
		$this->_skin_locations[]	= array(
										'path'	=> NAILS_PATH,
										'url'	=> NAILS_URL,
										'regex'	=> '/^blog-skin-(.*)$/'
									);

		//	App Skins
		$this->_skin_locations[]	= array(
										'path' => FCPATH . APPPATH . 'modules/blog/skins',
										'url' => site_url( APPPATH . 'modules/blog/skins', page_is_secure() )
									);
	}


	// --------------------------------------------------------------------------


	/**
	 * Fetches all available shipping drivers
	 * @param  boolean $refresh Fetchf rom refresh - skip the cache
	 * @return array
	 */
	public function get_available( $refresh = FALSE )
	{
		if ( ! is_null( $this->_available ) && ! $refresh ) :

			return $this->_available;

		endif;

		//	Reset
		$this->_available = array();

		// --------------------------------------------------------------------------

		//	Look for skins, where a skin has the same name, the last one found is the
		//	one which is used

		$this->load->helper( 'directory' );

		//	Take a fresh copy
		$_skin_locations = $this->_skin_locations;

		//	Sanitise
		for ( $i = 0; $i < count( $_skin_locations ); $i++ ) :

			//	Ensure path is present and has a trailing slash
			if ( isset( $_skin_locations[$i]['path'] ) ) :

				$_skin_locations[$i]['path'] = substr( $_skin_locations[$i]['path'], -1, 1 ) == '/' ? $_skin_locations[$i]['path'] : $_skin_locations[$i]['path'] . '/';

			else :

				unset( $_skin_locations[$i] );

			endif;

			//	Ensure URL is present and has a trailing slash
			if ( isset( $_skin_locations[$i]['url'] ) ) :

				$_skin_locations[$i]['url'] = substr( $_skin_locations[$i]['url'], -1, 1 ) == '/' ? $_skin_locations[$i]['url'] : $_skin_locations[$i]['url'] . '/';

			else :

				unset( $_skin_locations[$i] );

			endif;

		endfor;

		//	Reset array keys, possible that some may have been removed
		$_skin_locations = array_values( $_skin_locations );

		foreach( $_skin_locations AS $skin_location ) :

			$_path	= $skin_location['path'];
			$_skins	= directory_map( $_path, 1 );

			if ( is_array( $_skins ) ) :

				foreach( $_skins AS $skin ) :

					//	do we need to filter out non skins?
					if ( ! empty( $skin_location['regex'] ) ) :

						if ( ! preg_match( $skin_location['regex'], $skin ) ) :

							log_message( 'debug', '"' . $skin . '" is not a blog skin.' );
							continue;

						endif;

					endif;

					// --------------------------------------------------------------------------

					//	Exists?
					if ( file_exists( $_path . $skin . '/config.json' ) ) :

						$_config = @json_decode( file_get_contents( $_path . $skin . '/config.json' ) );

					else :<commit_msg>Doing a directory check before attempting to map a directory (prevents logs filling up)<commit_after><?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Name:			blog_skin_model.php
 *
 * Description:		This model finds and loads blog skins
 *
 **/

/**
 * OVERLOADING NAILS' MODELS
 *
 * Note the name of this class; done like this to allow apps to extend this class.
 * Read full explanation at the bottom of this file.
 *
 **/

class NAILS_Blog_skin_model extends NAILS_Model
{
	protected $_available;
	protected $_skins;
	protected $_skin_locations;


	// --------------------------------------------------------------------------


	/**
	 * Construct the model.
	 */
	public function __construct()
	{
		parent::__construct();

		// --------------------------------------------------------------------------

		$this->_available = NULL;

		/**
		 * Skin locations
		 * The model will search these directories for skins; to add more directories extend this
		 * This must be an array with 2 indexes:
		 * `path`	=> The absolute path to the directory containing the skins (required)
		 * `url`	=> The URL to access the skin (required)
		 * `regex`	=> If the directory doesn't only contain skin then specify a regex to filter by
		 */

		if ( empty( $this->_skin_locations ) ) :

			$this->_skin_locations = array();

		endif;

		//	'Official' skins
		$this->_skin_locations[]	= array(
										'path'	=> NAILS_PATH,
										'url'	=> NAILS_URL,
										'regex'	=> '/^blog-skin-(.*)$/'
									);

		//	App Skins
		$this->_skin_locations[]	= array(
										'path' => FCPATH . APPPATH . 'modules/blog/skins',
										'url' => site_url( APPPATH . 'modules/blog/skins', page_is_secure() )
									);
	}


	// --------------------------------------------------------------------------


	/**
	 * Fetches all available shipping drivers
	 * @param  boolean $refresh Fetchf rom refresh - skip the cache
	 * @return array
	 */
	public function get_available( $refresh = FALSE )
	{
		if ( ! is_null( $this->_available ) && ! $refresh ) :

			return $this->_available;

		endif;

		//	Reset
		$this->_available = array();

		// --------------------------------------------------------------------------

		//	Look for skins, where a skin has the same name, the last one found is the
		//	one which is used

		$this->load->helper( 'directory' );

		//	Take a fresh copy
		$_skin_locations = $this->_skin_locations;

		//	Sanitise
		for ( $i = 0; $i < count( $_skin_locations ); $i++ ) :

			//	Ensure path is present and has a trailing slash
			if ( isset( $_skin_locations[$i]['path'] ) ) :

				$_skin_locations[$i]['path'] = substr( $_skin_locations[$i]['path'], -1, 1 ) == '/' ? $_skin_locations[$i]['path'] : $_skin_locations[$i]['path'] . '/';

			else :

				unset( $_skin_locations[$i] );

			endif;

			//	Ensure URL is present and has a trailing slash
			if ( isset( $_skin_locations[$i]['url'] ) ) :

				$_skin_locations[$i]['url'] = substr( $_skin_locations[$i]['url'], -1, 1 ) == '/' ? $_skin_locations[$i]['url'] : $_skin_locations[$i]['url'] . '/';

			else :

				unset( $_skin_locations[$i] );

			endif;

		endfor;

		//	Reset array keys, possible that some may have been removed
		$_skin_locations = array_values( $_skin_locations );

		foreach( $_skin_locations AS $skin_location ) :

			$_path	= $skin_location['path'];
			$_skins	= is_dir($_path) ? directory_map( $_path, 1 ) : array();

			if ( is_array( $_skins ) ) :

				foreach( $_skins AS $skin ) :

					//	do we need to filter out non skins?
					if ( ! empty( $skin_location['regex'] ) ) :

						if ( ! preg_match( $skin_location['regex'], $skin ) ) :

							log_message( 'debug', '"' . $skin . '" is not a blog skin.' );
							continue;

						endif;

					endif;

					// --------------------------------------------------------------------------

					//	Exists?
					if ( file_exists( $_path . $skin . '/config.json' ) ) :

						$_config = @json_decode( file_get_contents( $_path . $skin . '/config.json' ) );

					else :
{'fraction_non_alphanumeric': 0.23337091319052988, 'fraction_numerical': 0.0017537266691719905, 'mean_word_length': 2.0037622272385254, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, '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': '1339995', 'n_tokens_mistral': 2906, 'n_tokens_neox': 2316, 'n_words': 685}