<commit_before><?php
// (c) Copyright 2002-2010 by authors of the Tiki Wiki/CMS/Groupware Project
// 
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
  header("location: index.php");
  exit;
}

class ThemeGenLib
{
	private $currentTheme;	// ThemeGenTheme

	public function ThemeGenLib() {
		global $prefs;
		
		if (!empty($prefs['themegenerator_theme'])) {
			$t = $prefs['themegenerator_theme'];
		} else {
			$t = '';
		}
		$this->currentTheme = new ThemeGenTheme($t);
	}
	
	public function setupEditor() {
		global $headerlib, $smarty, $prefs;
		
		// tiki themegen include
		$headerlib->add_jsfile('lib/jquery_tiki/tiki-themegenerator.js');
		
		// set up colorpicker
		$headerlib->add_cssfile('lib/jquery/colorpicker/css/colorpicker.css');
		$headerlib->add_cssfile('lib/jquery_tiki/colorpicker/layout.css');
	
		$headerlib->add_jsfile('lib/jquery/colorpicker/js/colorpicker.js');
		$headerlib->add_jsfile('lib/jquery/colorpicker/js/eye.js');
		$headerlib->add_jsfile('lib/jquery/colorpicker/js/utils.js');
		$headerlib->add_jsfile('lib/jquery/colorpicker/js/layout.js');
		
		// colour lib
		$headerlib->add_jsfile('lib/jquery/jquery.color.js');
		
		
		$data = $this->currentTheme->loadPref();
		
		if (!empty($_REQUEST['tg_css_file'])) {
			$css_file = $_REQUEST['tg_css_file'];
		} else if ($data) {
			$css_files = array_keys($data['files']);
			$css_file_found = false;
			foreach ( $css_files as $css_file) {
				foreach( $headerlib->cssfiles as $files) {
					if (in_array($css_file, $files)) {
						$css_file_found = true;
						break 2;
					}
				}
			}
			if ( !$css_file_found ) {
				$css_file = ''; //$css_file[0];
			}
		} else {
//			$css_file = $prefs['themegenerator_css_file'];
			$css_file = '';
		}
		$mincss .= $headerlib->minify_css( $css_file );	// clean out comments etc
		
		$num = preg_match_all( '/[^-]color:([^\};!]*?)[;\}!]/i', $mincss, $matches );
		if ($num) {
			$colors = $this->currentTheme->processMatches( $matches[1], $css_file, 'fgcolors' );
		} else {
			$colors = array();
		}
		$num = preg_match_all('/background(?:-color)?:.*?(#[0-9A-F]{3,6})[\s;\}\!]/i', $mincss, $matches);
		if ($num) {
			$bgcolors = $this->currentTheme->processMatches( $matches[1], $css_file, 'bgcolors' );
		} else {
			$bgcolors = array();
		}		
		$num = preg_match_all('/border(?:-.*?)?:.*?(#[0-9A-F]{3,6})[\s;\}\!]/i', $mincss, $matches);
		if ($num) {
			$bordercolors = $this->currentTheme->processMatches( $matches[1], $css_file, 'bordercolors' );
		} else {
			$bordercolors = array();
		}		
		preg_match_all('/font-size:.*?([\d\.]*[^;\} ]*)/i', $mincss, $matches);
		$fontsizes = $this->currentTheme->processMatches( $matches[1], $css_file, 'fontsize' );
		
		// array for smarty to loop through
		$tg_data = array(
			'colors' => array(
				'types' => array(
					'fgcolors' => array(
						'items' => $colors,
						'title' => tra('Foreground Colors:'),
					),
					'bgcolors' => array(
						'items' => $bgcolors,
						'title' => tra('Background Colors:'),
					),<commit_msg>[FIX] themegen: Better regexp for borders<commit_after><?php
// (c) Copyright 2002-2010 by authors of the Tiki Wiki/CMS/Groupware Project
// 
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
  header("location: index.php");
  exit;
}

class ThemeGenLib
{
	private $currentTheme;	// ThemeGenTheme

	public function ThemeGenLib() {
		global $prefs;
		
		if (!empty($prefs['themegenerator_theme'])) {
			$t = $prefs['themegenerator_theme'];
		} else {
			$t = '';
		}
		$this->currentTheme = new ThemeGenTheme($t);
	}
	
	public function setupEditor() {
		global $headerlib, $smarty, $prefs;
		
		// tiki themegen include
		$headerlib->add_jsfile('lib/jquery_tiki/tiki-themegenerator.js');
		
		// set up colorpicker
		$headerlib->add_cssfile('lib/jquery/colorpicker/css/colorpicker.css');
		$headerlib->add_cssfile('lib/jquery_tiki/colorpicker/layout.css');
	
		$headerlib->add_jsfile('lib/jquery/colorpicker/js/colorpicker.js');
		$headerlib->add_jsfile('lib/jquery/colorpicker/js/eye.js');
		$headerlib->add_jsfile('lib/jquery/colorpicker/js/utils.js');
		$headerlib->add_jsfile('lib/jquery/colorpicker/js/layout.js');
		
		// colour lib
		$headerlib->add_jsfile('lib/jquery/jquery.color.js');
		
		
		$data = $this->currentTheme->loadPref();
		
		if (!empty($_REQUEST['tg_css_file'])) {
			$css_file = $_REQUEST['tg_css_file'];
		} else if ($data) {
			$css_files = array_keys($data['files']);
			$css_file_found = false;
			foreach ( $css_files as $css_file) {
				foreach( $headerlib->cssfiles as $files) {
					if (in_array($css_file, $files)) {
						$css_file_found = true;
						break 2;
					}
				}
			}
			if ( !$css_file_found ) {
				$css_file = ''; //$css_file[0];
			}
		} else {
//			$css_file = $prefs['themegenerator_css_file'];
			$css_file = '';
		}
		$mincss .= $headerlib->minify_css( $css_file );	// clean out comments etc
		
		$num = preg_match_all( '/[^-]color:([^\};!]*?)[;\}!]/i', $mincss, $matches );
		if ($num) {
			$colors = $this->currentTheme->processMatches( $matches[1], $css_file, 'fgcolors' );
		} else {
			$colors = array();
		}
		$num = preg_match_all('/background(?:-color)?:.*?(#[0-9A-F]{3,6})[\s;\}\!]/i', $mincss, $matches);
		if ($num) {
			$bgcolors = $this->currentTheme->processMatches( $matches[1], $css_file, 'bgcolors' );
		} else {
			$bgcolors = array();
		}		
		$num = preg_match_all('/border(?:-.*)?:.*(#[0-9A-F]{3,6})[\s;\}\!]/Umis', $mincss, $matches);
		if ($num) {
			$bordercolors = $this->currentTheme->processMatches( $matches[1], $css_file, 'bordercolors' );
		} else {
			$bordercolors = array();
		}		
		preg_match_all('/font-size:.*?([\d\.]*[^;\} ]*)/i', $mincss, $matches);
		$fontsizes = $this->currentTheme->processMatches( $matches[1], $css_file, 'fontsize' );
		
		// array for smarty to loop through
		$tg_data = array(
			'colors' => array(
				'types' => array(
					'fgcolors' => array(
						'items' => $colors,
						'title' => tra('Foreground Colors:'),
					),
					'bgcolors' => array(
						'items' => $bgcolors,
						'title' => tra('Background Colors:'),
					),
{'fraction_non_alphanumeric': 0.19975805232118554, 'fraction_numerical': 0.00665356116739755, 'mean_word_length': 3.67090395480226, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, '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': '4359238', 'n_tokens_mistral': 2776, 'n_tokens_neox': 2392, 'n_words': 445}