<?php

class faviconatorapp extends plugin {

	protected function load () {
		$this -> title = 'Faviconator';
		$this -> author = 'Ovalio';
		$this -> url = 'http://opiner-cms.net/';
		$this -> description = 'Zmeňte ikonku Vašej stránky, ktorá sa zobrazuje pri adrese v prehliadači.';
		$this -> modes = array ('application');
		$this -> cache = false;
		$this -> redactors = false;
		$this -> values = array ();
		$this -> tables = array ();
	}

	public function application () {
		global $_CONFIG, $_FILES, $_REQUEST;
		$out = '';
		if (isset ($_REQUEST['delete'])) {
			if (ConfigUpdate ('favicon', '') and @unlink ('media/' . $_CONFIG['favicon']))
			$out .= GetIcon ('info', 'Ikonka webu bola úspešne odstránená');
			else $out .= GetIcon ('error', 'Pri odstraňovaní ikonky došlo k chybe');
		} else if (isset ($_FILES['favicon'])) {
			$iconname = strrpos ($_FILES['favicon']['name'], '.');
			$iconname = substr ($_FILES['favicon']['name'], $iconname + 1);
			if (substr ($_FILES['favicon']['type'], 0, 6) == 'image/' and $_FILES['favicon']['error'] == 0
			and move_uploaded_file ($_FILES['favicon']['tmp_name'], 'media/favicon.' . $iconname)
			and ConfigUpdate ('favicon', 'favicon.' . $iconname) and ConfigUpdate ('favicon_mime', $_FILES['favicon']['type']))
			$out .= GetIcon ('info', 'Ikonka webu bola úspešne pridaná');
			else $out .= GetIcon ('error', 'Pri pridávaní ikonky došlo k chybe');
		};
		$out .= '<form action="' . _SiteForm . '" method="post" enctype="multipart/form-data">'.n;
		if ($_CONFIG['favicon'] != '' and file_exists ('media/' . $_CONFIG['favicon'])) {
			$out .= '<img src="media/' . $_CONFIG['favicon'] . '" style="border:0;margin-left:15px;" /><br />
			<input type="checkbox" name="delete" value="delete" id="i1" /> <label for="i1">Odstrániť túto ikonku webu</label>'.n;
		} else {
			$out .= '<strong>Nahrať ikonku webu</strong>
			<input type="file" name="favicon" accept="image/*" />'.n;
		};
		$out .= '<center><input type="submit" value="Použiť nastavenia" name="ok" /></center>
		</form>';
		return $out;
	}
};