<?php
/* Smarty version 4.5.2, created on 2024-05-10 23:12:22
  from '/Users/nikolaimv/Sites/yzb.loc/admin/templates/views/favicon/index.tpl' */

/* @var Smarty_Internal_Template $_smarty_tpl */
if ($_smarty_tpl->_decodeProperties($_smarty_tpl, array (
  'version' => '4.5.2',
  'unifunc' => 'content_663e6386e1a699_21542689',
  'has_nocache_code' => false,
  'file_dependency' => 
  array (
    '6c56eb8fbe3295dc2f9dc932eb334a06dcb2b352' => 
    array (
      0 => '/Users/nikolaimv/Sites/yzb.loc/admin/templates/views/favicon/index.tpl',
      1 => 1715364170,
      2 => 'file',
    ),
  ),
  'includes' => 
  array (
    'file:components/page-header.tpl' => 1,
    'file:uploads_init.tpl' => 1,
  ),
),false)) {
function content_663e6386e1a699_21542689 (Smarty_Internal_Template $_smarty_tpl) {
if (!empty($_smarty_tpl->tpl_vars['html_code']->value)) {
echo '<script'; ?>
 src="/admin/assets/js/vendor/editors/ace/ace.js"><?php echo '</script'; ?>
>
<?php echo '<script'; ?>
>
	const Ace = function() {
		const _componentAce = function() {
			if (typeof ace == 'undefined') {
				console.warn('Warning - ace.js is not loaded.');
				return;
			}

			ace.config.set('theme', 'ace/theme/limitless');
			ace.config.set('showPrintMargin', false);

			// HTML editor
			const html_editor = ace.edit('html_editor', {
				mode: 'ace/mode/html'
			});
		};

		return {
			init: function() {
				_componentAce();
			}
		}
	}();

	document.addEventListener('DOMContentLoaded', function() {
		Ace.init();
	});

<?php echo '</script'; ?>
>
<?php }?>
<div>

	<!-- Page header -->

    <?php $_smarty_tpl->smarty->ext->_capture->open($_smarty_tpl, "breadcrumb", null, null);?>
		<a href="<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['adminUrl']->value, ENT_QUOTES, 'UTF-8', true);?>
/favicon" class="breadcrumb-item"><?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['title']->value, ENT_QUOTES, 'UTF-8', true);?>
</a>
    <?php $_smarty_tpl->smarty->ext->_capture->close($_smarty_tpl);?>

    <?php $_smarty_tpl->smarty->ext->_capture->open($_smarty_tpl, "showBy", null, null);
$_smarty_tpl->smarty->ext->_capture->close($_smarty_tpl);?>

    <?php $_smarty_tpl->_subTemplateRender("file:components/page-header.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array('buttons'=>$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl, 'buttons'),'breadcrumb'=>$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl, 'breadcrumb'),'showBy'=>$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl, 'showBy')), 0, false);
?>
	<!-- /page header -->

    <div class="content">
        <div class="row"> 
            <div class="col-md-12">

    		    <div class="card border shadow-sm">
			        <div class="card-header d-flex flex-wrap">
				        <h6 class="mb-0">Основное</h6>
				        <div class="d-inline-flex ms-auto">
					        <a class="text-body" data-card-action="collapse"><i class="ph-caret-down"></i></a>
				        </div>
			        </div>
			        <div class="collapse show">
	                    <div class="card-body">
	                        <div class="row">
	                            <div class="col-md-6">
	                                <div class="form-group mb-3">
	                                    <label class="form-label">URL главного изображения</label>
										<div class="input-group">
	                                    	<input type="text" class="form-control" id="master_picture_url" name="master_picture_url" value="" placeholder="Путь к картинке"/>
											<button id="favicon-add" type="button" class="btn btn-sm btn-primary btn-favicon read-more" data-type="favicon" data-path="/" data-action="read_more">
												<i class="ph-image me-2"></i>Загрузить файл
											</button>
										</div>
										<div class="form-text text-muted">Добавьте квадратную картину размером не менее 70 х 70 (рекомендованный размер: 260x260 или более)<br>
											Если изображение находится на вашем жестком диске, вы можете оставить это поле пустым и загрузить изображение из RealFaviconGenerator.</div>
	                                </div>
									<div class="form-group text-end mb-3">
										<form role="form" method="post" action="https://realfavicongenerator.net/api/favicon_generator" id="generate_favicon_form">
											<input type="hidden" name="json_params" id="json_params"/>
											<button type="submit" id="generate_favicon_button" class="btn btn-outline-success">Генерировать favicon</button>
										</form>
									</div>


									<div class="form-group mb-3">
										<?php if (!empty($_smarty_tpl->tpl_vars['html_code']->value)) {?>
											<label class="form-label">Вставьте следующий код в <code> head </code> ваших страниц</label>
											<pre class="rounded border " id="html_editor" style="height: 200px;"><?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['html_code']->value, ENT_QUOTES, 'UTF-8', true);?>
</pre>
										<?php }?>
									</div>

	                            </div>

								<div class="col-md-6">
									<div class="form-group mb-3">
										<label class="form-label">Текущий значок <br>
											<span class="fs-sm text-muted">
												<?php if (!empty($_smarty_tpl->tpl_vars['preview_url']->value)) {?>
													Favicon установлен и готов к работе.
												<?php } else { ?>
													Ни один favicon пока не настроен.
												<?php }?>
											</span>
										</label>
										<?php if (!empty($_smarty_tpl->tpl_vars['preview_url']->value)) {?>
											<div class="text-center">
												<div class="d-inline-block">
													<img class="img-fluid rounded" src="<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['preview_url']->value, ENT_QUOTES, 'UTF-8', true);?>
" alt="favicon preview">
												</div>
											</div>

										<?php }?>
									</div>
								</div>


	                        </div>
	                    </div>
			        </div>
    		    </div>

            </div>

        </div>
    </div>
</div>

<?php $_smarty_tpl->_subTemplateRender('file:uploads_init.tpl', $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), 0, false);
?>

<?php echo '<script'; ?>
>
    $(document).ready(function () {
        <?php if ((isset($_smarty_tpl->tpl_vars['messages']->value['saved']))) {?> new Noty({ text: 'Favicon установлен и готов к работе.', type: 'success' }).show(); <?php }?>
        <?php if ((isset($_smarty_tpl->tpl_vars['errors']->value['not_saved']))) {?> new Noty({ text: 'Произошла ошибка', type: 'error', timeout: 1500 }).show(); <?php }?>
        <?php if ((isset($_smarty_tpl->tpl_vars['errors']->value['error']))) {?> new Noty({ text: 'Произошла ошибка', type: 'error', timeout: 1500 }).show(); <?php }?>

    });
<?php echo '</script'; ?>
>
<?php echo '<script'; ?>
 type="text/javascript">
	var picData = null;

	// See http://stackoverflow.com/questions/934012/get-image-data-in-javascript
	// Credits: Matthew Crumley
	function getBase64Image(img) {
		// Create an empty canvas element
		var canvas = document.createElement("canvas");
		canvas.width = img.width;
		canvas.height = img.height;

		// Copy the image contents to the canvas
		var ctx = canvas.getContext("2d");
		ctx.drawImage(img, 0, 0);

		// Get the data-URL formatted image
		// Firefox supports PNG and JPEG. You could check img.src to
		// guess the original format, but be aware the using "image/jpg"
		// will re-encode the image.
		var dataURL = canvas.toDataURL("image/png");

		return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
	}

	function computeJson() {
		var params = { favicon_generation: {
				api_key: "87d5cd739b05c00416c4a19cd14a8bb5632ea563",
				callback: { },
				master_picture: { },
				files_location: { }
			}
		};

		params.favicon_generation.callback.type = 'url';
		params.favicon_generation.callback.url = "https://" + window.location.hostname + "/admin/favicon?action=back";
		params.favicon_generation.callback.short_url =  'true';
		params.favicon_generation.callback.path_only =  'true';
		params.favicon_generation.callback.custom_parameter = 'favicon_generation';

		if ($('#master_picture_url').val().length <= 0) {
			params.favicon_generation.master_picture.type = "no_picture";
			params.favicon_generation.master_picture.demo = true;
		}
		else if (pictureContent != null) {
			params.favicon_generation.master_picture.type = "inline";
			params.favicon_generation.master_picture.content = pictureContent;
		}
		else {
			params.favicon_generation.master_picture.type = "url";
			params.favicon_generation.master_picture.url = $('#master_picture_url').val();
		}

		params.favicon_generation.files_location.type = 'path';
		params.favicon_generation.files_location.path = "/themes/assets/favicon/";



		return params;
	}

	$(document).ready(function() {
		let pictureUrl = document.getElementById('master_picture_url')

		console.log(pictureUrl.value)
		let img = new Image;
		img.src = pictureUrl.value;

		img.onload = function() {
			picData = getBase64Image(img);

			$('#generate_favicon_button').removeAttr('disabled');
		}

		$('#generate_favicon_form').submit(function(e) {
			$('#json_params').val(JSON.stringify(computeJson()));
		});
	});

	let pictureContent = null;
	let pictureContentTimestamp = null;

	function prepareInlinePicture(pictureUrl) {
		let timestamp = new Date().getTime();
		pictureContentTimestamp	= timestamp;

		$('#generate_favicon_button').attr('disabled', 'disabled');
		$('#generate_favicon_button').val("Preparing master picture...");

		pictureContent = null;

		urlToBase64(pictureUrl, function(content) {
			if (content != null) {
				pictureContent = content;
			}
			restoreGenerateFaviconButton();
		});

		setTimeout(function() {
			if (pictureContentTimestamp == timestamp) {
				restoreGenerateFaviconButton();
			}
		}, 3000);
	}

	function restoreGenerateFaviconButton() {
		$('#generate_favicon_button').removeAttr('disabled');
		$('#generate_favicon_button').val("Generate favicon");
	}


	function urlToBase64(url, callback) {
		var img = new Image();
		img.onload = function() {
			callback(getBase64Image(img));
		}
		img.onerror = function() {
			callback(null);
		}
		img.src = url;
	}


<?php echo '</script'; ?>
>

<?php }
}
