
<?php  

	
	include "root.php";
	$sg_root=trim(trim(trim($sg_root),'/'));
	if ($sg_root!="") $sg_root=$sg_root."/";
	function sg_linklist($PG) {foreach ($PG as $k=>$v){
		if (is_file('../../'.$v.'.html')) $e='.html';
		elseif (is_file('../../'.$v.'.php')) $e='.php'; else continue;
		$z=$v; $pt="../../sg_cm/content/".$v."/zagl"; $z0=@file_get_contents($pt);
		if ($z0!='') $z=mb_substr($z0,0,25);
	if(strpos($v,"'")===false) echo '{title: \''.$z.'\', value: "'.$v.$e.'"},';}
	}
	function sg_classlist($indx){
		if (is_file('../../sg_cm/css/classlist.php')){
		include('../../sg_cm/css/classlist.php');}
		echo "{title: '--------', value: ''},";
		//if (!isset($indx) && is_file('db/zagl')){include('db/zagl');} 
		if (isset($indx) && is_file('../../sg_cm/content/'.$indx.'/classlist.php')){
		include('../../sg_cm/content/'.$indx.'/classlist.php');}
	}
	function file_list_all($dir) {$file_array=array();
		if (is_dir($dir))
		{$d=$dir.'/*';
			$file_array=glob($d);
			if (!$file_array || $file_array===FALSE) $file_array=array();
		foreach ($file_array as $k=>$v) {$file_array[$k]=basename($v);}}
		return $file_array;
	}
?>
<script type="text/javascript" src="../../sg_cm/tinymce/tinymce.min.js"></script>
<script>
	
	tinymce.init({
		protect: [
		/<div id="" class="sg_fotoGal"[\s\S]*?<\/div><\/div>/gm ,
		/<\?[\s\S]*?\?>/gm ,// Protect php code
		/<script[\s\S]*?<\/script>/gm ,// Protect script code
		/<i[\s\S]*?class=[\s\S]*?<\/i>/gm // Protect i code иконочные шрифты
		],
		selector: "textarea.mceEditor",
		fontsize_formats: "8px 9px 10px 11px 12px 13px 14px 16px 18px 20px 22px 24px 26px 28px 30px 32px 34px 36px 42px 48px 54px 60px 66px 72px",
		font_formats: "<? echo $tmc_font_families;?>",
		theme: "modern",
		width: 700,
		height: 600,
//		forced_root_block : 'p',
		remove_trailing_brs: false,
		style_formats_merge: true,
		formats: {
			alignleft: {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'tm_left'},
			aligncenter: {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'tm_cntr'},
			alignright: {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'tm_right'},
			alignjustify: {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'tm_full'},

		},
		
		relative_urls : <? echo $tmc_relative_urls;?>,
		convert_urls: true,
		allow_script_urls:true,
		document_base_url : "http://<?php echo $_SERVER['SERVER_NAME']."/".$sg_root;?>",
		content_css : " <?php echo $tmc_content_css_files; if(is_file('../../pcss/'.$CPAT.'.css')) {echo 'pcss/'.$CPAT.'.css, ';}
		?>sg_cm/css/site_tinymce.css <?php if(is_file('../../sg_cm/content/'.$CPAT.'/css.css')) {echo ', sg_cm/content/'.$CPAT.'/css.css ';}?>",
		body_class: "tmce",
		body_id: "sg_tinymce",
		
		
		autoresize_max_height : "700" ,
		language : 'ru',
		plugins: [
		"colorpicker advlist autolink link image imagetools lists charmap hr  pagebreak  ",
		"searchreplace visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
		"table contextmenu template paste textcolor autoresize anchor template filemanager "
		],
		link_list: [
		{title: 'Ссылка на якорь', value: '#'},
        {title: 'Отправить e-mail', value: 'mailto:ya@ya.ru?subject=&body='},
        {title: 'Распечатать страницу', value: 'javascript:window.print()'},
		{title: 'Окно сообщения', value: 'javascript:x5engine.utils.popup({text: \'Сообщение\', graphics: true, background: \'#000000\', width: \'30%\'})'},
		{title: 'Лента RSS', value: 'x5feed.xml'},
		{title: 'Блог', value: 'blog/index.html'},
		{title: 'Карта сайта', value: 'imsitemap.html'},
		<?php echo $tmc_add_link_list; ?>
		<?php sg_linklist($PG);?>
		
		], 
		image_class_list: [
		{title: 'Нет', value: 'null'},
		{title: 'Адаптивный размер картинки', value: 'sg_adaptive'},
		<?php echo $tmc_img_class_list; ?>
		<?php sg_classlist($indx);?>		
		],
		
		table_class_list: [ 
        {title: 'Нет', value: ''}, <?php echo $tmc_table_class_list; ?>
        <?php sg_classlist($indx);?>
		],
		table_cell_class_list: [ 
        {title: 'Нет', value: ''}, <?php echo $tmc_table_class_list; ?>
        <?php sg_classlist($indx);?>
		],
		table_raw_class_list: [ 
        {title: 'Нет', value: ''}, <?php echo $tmc_table_class_list; ?>
        <?php sg_classlist($indx);?>
		],
		
		
		link_class_list: [ 
		{title: 'Стиль ссылок GScms', value: 'gsLink'},
        {title: 'Нет', value: ''},
        {title: 'Галерея LightBox', value: 'sg_gallery'},
		{title: 'Стиль ссылок WebsiteX5', value: 'imCssLink'},
		<?php echo $tmc_link_class_list; ?>
		<?php sg_classlist($indx);?>
		],
	    target_list: [
        {title: 'Не задано', value: ''},
        {title: 'То же окно', value: '_self'},
        {title: 'Новое окно', value: '_blank'}
		],
	    rel_list: [
		{title: 'Нет', value: ''},
        {title: 'Галерея LightBox', value: 'sg_gallery'},
		{title: 'alternate', value: 'alternate'},
		{title: 'author', value: 'author'},
		{title: 'bookmark', value: 'bookmark'},
		{title: 'help', value: 'help'},
		{title: 'license', value: 'license'},
		{title: 'next', value: 'next'},
		{title: 'nofollow', value: 'nofollow'},
		{title: 'noreferrer', value: 'noreferrer'},
		{title: 'prefetch', value: 'sg_gallery'},
		{title: 'prev', value: 'prev'},
		{title: 'search', value: 'search'},
		{title: 'tag', value: 'tag'}
		],
		
		link_context_toolbar: true,
		visualblocks_default_state: true,
		preview_styles: 'font-family font-size font-weight font-style text-decoration text-transform  border border-radius outline text-shadow',
		menubar: "edit insert view format table tools ",
		image_advtab: true,
		image_title: true,
		image_caption: true,
		
		images_upload_url: '../../sg_cm/sg_cm/upload.php?CPAT=<? echo $CPAT; ?>',
		automatic_uploads: true,
		images_reuse_filename: true,
		
		extended_valid_elements: 'a[onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|rel|rev|charset|href|lang|tabindex|accesskey|type|target|class|id|title|onclick|style],div[align|style|rel|class|id|title|onclick|ondblclick|onmouseover]',
		
		setup :  
		function(ed) {
		
		    ed.addButton('mybutton', {
      type: 'menubutton',
      text: 'My button',
      icon: false,
      menu: [{
        text: 'Menu item 1',
        onclick: function() {
          ed.insertContent('&nbsp;<strong>Menu item 1 here!</strong>&nbsp;');
        }
      }, {
        text: 'Menu item 2',
        onclick: function() {
          ed.insertContent('&nbsp;<em>Menu item 2 here!</em>&nbsp;');
        }
      }]
    });
		
		
		
			ed.on('init', function () { 
				$("div.mce-toolbar.mce-last").hide();
			});
			ed.addMenuItem('EditMenu', {
				text: 'Вкл. редактирование меню',
				context: 'tools',
				onclick: function() {
					$("div.mce-toolbar.mce-last").toggle();$("div.mce-toolbar.mce-first").toggle();
				}
			});
			ed.addButton('DisableMenuPanel', {
				title : 'Выкл. редактирование меню',
				text : 'Выкл. панель',
				icon: false,
				onclick: function() { $("div.mce-toolbar.mce-last").toggle();$("div.mce-toolbar.mce-first").toggle();
				}
			});
			
			ed.addButton('DisableStMn', {
				title : 'Вкл./Откл. стиль',
				text: "Стиль", menubar: true,
				onclick: function() {var obj=$("#textfield_ifr").contents().find("div.sg_Menu>ul");
				obj.toggleClass("sg_MenuUl");}
			});	
			
			ed.addButton('CreateMenu', {
				title : 'Создать меню',
				icon: "numlist", menubar: true,
				onclick: function() { 
					ed.insertContent('<div class="sg_Menu"><ul class=sg_MenuUl><li>Пункт меню</li><li>Пункт меню</li></ul> </div>');
				}
			});	
			ed.addButton('CreateUL', {
				title : 'Добавить раздел меню',
				
				icon: "bullist", menubar: true,
				onclick: function() {
					ed.insertContent('<ul><li>Пункт меню</li><li>Пункт меню</li></ul> ');
				}
			});	
			ed.addButton('CreateLi', {
				title : 'Добавить пункт меню',
				icon: "hr", menubar: true,
				onclick: function() {
					ed.insertContent('<li>Пункт меню</li>');
				}
			});	
			ed.addButton('Create2xMenu', {
				title : 'Вставить шаблон меню',
				icon: false, menubar: true, text:'Шаблон меню',
				onclick: function() {
					ed.insertContent('<div class="sg_Menu"><ul class="sg_MenuUl"><li><a href="#">Главная</a></li><li><a href="#">Шаблоны, рецепты +</a><ul><li><a href="#">Шаблоны, заготовки +</a><ul><li><a href="#">Шаблон 1</a></li><li><a href="#">Шаблон 2</a></li><li><a href="#">Шаблон 3</a></li><li><a href="#">Шаблон 4</a></li><li><a href="#">Шаблон 5</a></li><li><a href="#">Шаблон 6</a></li><li><a href="#">Шаблон 7</a></li><li><a href="#">Шаблон 8</a></li></ul></li><li><a href="#">Рецепты HTML</a></li><li><a href="#">Рецепты CSS</a></li></ul></li><li><a href="#">Менюшки +</a><ul><li><a href="#">Вертикальные +</a><ul><li><a href="#">Вертикальное меню 1</a></li><li><a href="#">Вертикальное меню 2</a></li><li><a href="#">Вертикальное меню 3</a></li><li><a href="#">Вертикальное меню 4</a></li><li><a href="#">Вертикальное меню 5</a></li></ul></li><li><a href="#">Горизонтальные +</a><ul><li><a href="#">Горизонтальное меню 1</a></li><li><a href="#">Горизонтальное меню 2</a></li><li><a href="#">Горизонтальное меню 3</a></li></ul></li></ul></li><li><a href="#">Контакт</a></li></ul></div>');
				}
			});	
			
			
			// Add a custom button
			ed.addButton('spoiler', {
				title : 'Вставить спойлер',
				text :"S",
				icon: false,
				menubar: true,
				onclick: function() {
					ed.insertContent('<div class="sg_spoiler"><div>Заголовок спойлера</div><div> <p> Тут находится ваш контент, который планируется прятать под спойлер. </p></div></div>');
				}
			});
			ed.addButton('gallery', {
				title : 'Галерея "LightBox"',
				image : '../../sg_cm/sg_images/16_gallery.png',
				icon: true, menubar: true,
				onclick: function() {
					ed.insertContent('<div class="sg_gallery"> </div>');
				}
			});
			ed.addButton('colortable', {
				title : 'Цветовые коды',
				image : '../../sg_cm/sg_images/tint.png',
				icon: true,
				onclick: function() {
					ed.windowManager.open({
						title: 'Цветовые коды',
						url: '../../sg_cm/set/rgb.html',
						width: 564,
						height: 200
					});
				}
			});	
			
			ed.addButton('Galleries', {
				type: 'splitbutton',
				image : '../../sg_cm/sg_images/040-file-picture.png',
				title : 'Редактировать/вставить галерею',
				icon: true,
				onclick: 
				function() {
					ed.windowManager.open({
						title: 'Фотогалереи',
						url: '../../sg_cm/sg_foto/adm.php',
						width: 1000,
						height: 740
					});
				},
				
				<?php $galList=file_list_all('../../sg_cm/upload/gs_foto/set');	  
				?>
				menu: [
				<?php 
					foreach ($galList as $k=>$v){$v1=file('../../sg_cm/upload/gs_foto/db/news/'.$v);?>
					{text: '<?php echo  trim($v1[2]);?>',
						onclick: function() {
							ed.insertContent('<div ondblclick="parent.openGalEditor(<?php echo $v;?>);" id= "<?php echo $v;?>" class="sg_fotoGal" ><\?php require($root1."sg_cm/upload/gs_foto/set/<?php echo $v;?>");\?></div>');
						}
					}, <?php }?>
					
					]
			});
			
			ed.addButton('Background', {
				title : 'Переключить цвет фона редактора',
				image : '../../sg_cm/sg_images/fonb.png',
				icon: true,
				onclick: function() { obj=tinymce.activeEditor.getBody();
					if(obj.style.backgroundColor=="black") {obj.style.backgroundColor = "white";} else if(obj.style.backgroundColor=="rgb(159, 159, 159)"){obj.style.backgroundColor="black";} else{obj.style.backgroundColor="rgb(159, 159, 159)";} localStorage.setItem('bcolor',obj.style.backgroundColor);
				}
			});
			
		},	
		
		toolbar1: "| undo redo |  styleselect | fontselect fontsizeselect | bold italic  | forecolor backcolor charmap | colortable | alignleft aligncenter alignright alignjustify mybuttonL mybuttonR | bullist numlist outdent indent | filemanager link image gallery media spoiler | <? echo 'Galleries';?> | code Background |", 
		
		toolbar2: "| undo redo | CreateMenu CreateUL CreateLi Create2xMenu | DisableStMn | link | code Background | DisableMenuPanel | " ,  
		toolbar_items_size : 'l',
		
		file_browser_callback: function(field_name, url, type, win) { 
			var fm_type=0;  var papka='';
			if (url.substr(0, 1)=='/') url=url.substr(1, url.length-1);
			var papka_arr = new Array ('gallery','files','images','videos');
			var ar_url = url.split("/"); 
			if (ar_url[0]=='sg_cm'  &&  ar_url[1]=='upload') 
			{ 
				var papka='';
				var folder = ar_url.slice(2, ar_url.length-1).join('/'); 
			}
			else {if($.inArray(ar_url[0], papka_arr) > -1){ 
				var papka=ar_url[0];
				var folder = ar_url.slice(1, ar_url.length-1).join('/'); 
			}
			else {var papka=''; var folder='';}
			}
			var typeTitle='Менеджер ';
			if (type=='image') { typeTitle+='изображений'; fm_type=1;}
			if (type=='file') { typeTitle+='файлов'; fm_type=2;}
			if (type=='media') { typeTitle+='видео/аудио'; fm_type=3;}
			tinymce.activeEditor.windowManager.open({
				title: typeTitle,
				url: '../../sg_cm/tinymce/plugins/filemanager/dialog.php?papka='+papka+'&editor='+field_name+'&lang=ru&type='+fm_type+'&fldr='+folder,
				classes:'filemanager',width:900,height:600,inline:1
			});
			
			
		}	
		
	}); 
	
	tinymce.init({
		selector: "textarea.mceImage",
		auto_focus: "textbloka",
		theme: "modern",
		width: 700,
		relative_urls : true,
		document_base_url : "http://<?php echo $_SERVER['SERVER_NAME']."/".$sg_root;?>",
		content_css : "style/reset.css, sg_cm/css/tinymce.css, <?php if(is_file('../../pcss/'.$CPAT.'.css')) {echo 'pcss/'.$CPAT.'.css, ';} 
		?>sg_cm/css/site_tinymce.css",
		autoresize_max_height : "700" ,
		autoresize_min_height : "20" ,
		language : 'ru',
		allow_script_urls:true,
		invalid_elements : "p",
		visual: false,
		plugins: [
		"advlist link image lists",
		"code fullscreen",
		"contextmenu autoresize visualblocks"
		],
		protect: [ /<div[\s\S]*?<\/div>/g
		],
		contextmenu: true,
		statusbar : false,
		visualblocks_default_state: true,
		menubar: false,
		image_advtab: true,
		extended_valid_elements : "a[onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|rel|rev|charset|href|lang|tabindex|accesskey|type|target|class|title|onclick]",
		link_list: [
		{title: 'Ссылка на якорь', value: '#'},
        {title: 'Отправить e-mail', value: 'mailto:ya@ya.ru?subject=&body='},
        {title: 'Распечатать страницу', value: 'javascript:window.print()'},
		{title: 'Окно сообщения', value: 'javascript:x5engine.utils.popup({text: \'Сообщение\', graphics: true, background: \'#000000\', width: \'30%\'})'},
		{title: 'Лента RSS', value: 'x5feed.xml'},
		{title: 'Блог', value: 'blog/index.html'},
		{title: 'Карта сайта', value: 'imsitemap.html'},
		<?php sg_linklist($PG);?>
		],
		
	    target_list: [
        {title: 'Не задано', value: ''},
        {title: 'То же окно', value: "_self"},
        {title: 'Новое окно', value: '_blank'}
		],
		link_title: false,
		
		setup :  
		function(ed) {
			ed.addButton('Background', {
				title : 'Переключить цвет фона редактора',
				image : '../../sg_cm/sg_images/fonb.png',
				icon: true,
				onclick: function() { obj=tinymce.activeEditor.getBody();
					if(obj.style.backgroundColor=="black") {obj.style.backgroundColor = "white";} else if(obj.style.backgroundColor=="rgb(159, 159, 159)"){obj.style.backgroundColor="black";} else{obj.style.backgroundColor="rgb(159, 159, 159)";} localStorage.setItem('bcolor',obj.style.backgroundColor);
				}
			});
			
			
		},	
		
		toolbar: "| undo redo | link image | fullscreen |  Background | ", 
		
		
		
	}); 
	
	tinymce.init({
		inline: "true",
		selector: ".mceFonttext",
		theme: "modern",
		relative_urls : true,
		fontsize_formats: "8px 9px 10px 11px 12px 13px 14px 16px 18px 20px 22px 24px 26px 28px 30px 32px 34px 36px 42px 48px 54px 60px 66px 72px",
		font_formats: "<? echo $tmc_font_families;?>",
		language : 'ru',
		style_formats_merge: true,
		invalid_elements : "p",
		plugins: ["textcolor colorpicker code"],
		menubar: false,
		width: 20,
		setup :  
		function(ed) {
			ed.addButton('Background', {
				title : 'Переключить цвет фона редактора',
				image : '../../sg_cm/sg_images/fonb.png',
				icon: true,
				onclick: function() { obj=tinymce.activeEditor.getBody();
					if(obj.style.backgroundColor=="black") {obj.style.backgroundColor = "white";} else if(obj.style.backgroundColor=="rgb(159, 159, 159)"){obj.style.backgroundColor="black";} else{obj.style.backgroundColor="rgb(159, 159, 159)";} localStorage.setItem('bcolor1',obj.style.backgroundColor);
				}
			});
		},	
		
		toolbar: " fontselect | fontsizeselect | forecolor |  Background | code |", 
		toolbar_items_size : 'small',
	}); 
	tinymce.init({
		inline: "true",
		fontsize_formats: "8px 9px 10px 11px 12px 13px 14px 16px 18px 20px 22px 24px 26px 28px 30px 32px 34px 36px 42px 48px 54px 60px 66px 72px",
		font_formats: "<? echo $tmc_font_families;?>",
		selector: ".mceFontlink",
		theme: "modern",
		relative_urls : true,
		language : 'ru',
		style_formats_merge: true,
		invalid_elements : "p",
		plugins: ["textcolor colorpicker code"],
		menubar: false,
		width: 20,
		setup :  
		function(ed) {
			ed.addButton('Background', {
				title : 'Переключить цвет фона редактора',
				image : '../../sg_cm/sg_images/fonb.png',
				icon: true,
				onclick: function() { obj=tinymce.activeEditor.getBody();
					if(obj.style.backgroundColor=="black") {obj.style.backgroundColor = "white";} else if(obj.style.backgroundColor=="rgb(159, 159, 159)"){obj.style.backgroundColor="black";} else{obj.style.backgroundColor="rgb(159, 159, 159)";} localStorage.setItem('bcolor2',obj.style.backgroundColor);
				}
			});
		},	
		toolbar: " underline | forecolor | backcolor | Background | code |", 
		toolbar_items_size : 'small',
	}); 
	
	
	tinymce.init({
		inline:"true",
		selector: "#onmover_t", 
		language : 'ru',
		invalid_elements : "p",
		contextmenu: true,
		menubar: false,
		toolbar: " bold italic ", 
		
	});   
	
	tinymce.init({
		inline:"true",
		selector: " #onmover_ts, #onmover_j, #onmover_j1, #onmover_oO, #onmover_oI, #onmover_rot, #onmover_i, #onmover_d, #pusto, #onmover_p, #onmover_p1, #href_pop, #href_tip",
		language : 'ru',
		menubar: false,
		invalid_elements : "p",
		toolbar: false, 
		toolbar_items_size : 'small',
	});  
</script>
