<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="https://ngcms.ru/forum/extern.php?action=feed&amp;tid=4194&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Next Generation CMS :: Форум поддержкиxfilds Не поддерживает формат webp]]></title>
		<link>https://ngcms.ru/forum/viewtopic.php?id=4194</link>
		<description><![CDATA[Самые свежие сообщения в xfilds Не поддерживает формат webp.]]></description>
		<lastBuildDate>Thu, 30 Jan 2020 12:45:01 +0000</lastBuildDate>
		<generator>FluxBB 1.5.11</generator>
		<item>
			<title><![CDATA[Re: xfilds Не поддерживает формат webp]]></title>
			<link>https://ngcms.ru/forum/viewtopic.php?pid=45065#p45065</link>
			<description><![CDATA[<p>Сомневаюсь, что самостоятельно это можно осуществить - то есть не включите поддержку WebP. Выходом может быть использование JavaScript&#039;ов, например, в canvas загонять, и из него уже изображение клепать <a href="/forum/go.php?link=https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL" rel="nofollow">https://developer.mozilla.org/en-US/doc … /toDataURL</a></p>]]></description>
			<author><![CDATA[dummy@example.com (rusiq)]]></author>
			<pubDate>Thu, 30 Jan 2020 12:45:01 +0000</pubDate>
			<guid>https://ngcms.ru/forum/viewtopic.php?pid=45065#p45065</guid>
		</item>
		<item>
			<title><![CDATA[Re: xfilds Не поддерживает формат webp]]></title>
			<link>https://ngcms.ru/forum/viewtopic.php?pid=45064#p45064</link>
			<description><![CDATA[<p>Варианта , чтобы включить [&quot;WebP Support&quot;]=&gt; bool(false) , самому, например через php.ini ? Или другой вариант? есть?&#160; А то тех поддержка молчит.</p>]]></description>
			<author><![CDATA[dummy@example.com (irbees2008)]]></author>
			<pubDate>Thu, 30 Jan 2020 11:09:31 +0000</pubDate>
			<guid>https://ngcms.ru/forum/viewtopic.php?pid=45064#p45064</guid>
		</item>
		<item>
			<title><![CDATA[Re: xfilds Не поддерживает формат webp]]></title>
			<link>https://ngcms.ru/forum/viewtopic.php?pid=45062#p45062</link>
			<description><![CDATA[<div class="codebox"><pre><code>array(13) {
 [&quot;GD Version&quot;]=&gt; string(26) &quot;bundled (2.1.0 compatible)&quot; 
[&quot;FreeType Support&quot;]=&gt; bool(true)
 [&quot;FreeType Linkage&quot;]=&gt; string(13) &quot;with freetype&quot;
 [&quot;GIF Read Support&quot;]=&gt; bool(true) 
[&quot;GIF Create Support&quot;]=&gt; bool(true) 
[&quot;JPEG Support&quot;]=&gt; bool(true)
 [&quot;PNG Support&quot;]=&gt; bool(true) 
[&quot;WBMP Support&quot;]=&gt; bool(true) 
[&quot;XPM Support&quot;]=&gt; bool(true) 
[&quot;XBM Support&quot;]=&gt; bool(true) 
[&quot;WebP Support&quot;]=&gt; bool(false) 
[&quot;BMP Support&quot;]=&gt; bool(true) 
[&quot;JIS-mapped Japanese Font Support&quot;]=&gt; bool(true) }</code></pre></div><p>Отключен</p>]]></description>
			<author><![CDATA[dummy@example.com (irbees2008)]]></author>
			<pubDate>Tue, 28 Jan 2020 13:31:58 +0000</pubDate>
			<guid>https://ngcms.ru/forum/viewtopic.php?pid=45062#p45062</guid>
		</item>
		<item>
			<title><![CDATA[Re: xfilds Не поддерживает формат webp]]></title>
			<link>https://ngcms.ru/forum/viewtopic.php?pid=45060#p45060</link>
			<description><![CDATA[<p>Может этой функции <strong>imagecreatefromwebp</strong> в расширении GD действительно нет на хостинге ???</p>]]></description>
			<author><![CDATA[dummy@example.com (rusiq)]]></author>
			<pubDate>Tue, 28 Jan 2020 12:37:46 +0000</pubDate>
			<guid>https://ngcms.ru/forum/viewtopic.php?pid=45060#p45060</guid>
		</item>
		<item>
			<title><![CDATA[Re: xfilds Не поддерживает формат webp]]></title>
			<link>https://ngcms.ru/forum/viewtopic.php?pid=45058#p45058</link>
			<description><![CDATA[<p>На хосте <img src="https://ngcms.ru/forum/img/smilies/hmm.png" width="15" height="15" alt="hmm" /></p><div class="codebox"><pre class="vscroll"><code>&lt;?php
//
// Copyright (C) 2006-2012 Next Generation CMS (http://ngcms.ru/)
// Name: upload.class.php
// Description: Files/Images upload managment
// Author: Vitaly Ponomarev
//
function get_item_dir($type) {
	global $config;
	switch ($type) {
		case &quot;image&quot;:
			return $config[&#039;images_dir&#039;];
		case &quot;file&quot;:
			return $config[&#039;files_dir&#039;];
		case &quot;avatar&quot;:
			return $config[&#039;avatars_dir&#039;];
		case &quot;photo&quot;:
			return $config[&#039;photos_dir&#039;];
		default:
			return false;
	}
}
class file_managment {
	// CONSTRUCTOR
	function file_managment() {
		// Load additional LANG file
		$lang = loadLang(&#039;files&#039;);
		return;
	}
	// Get limits
	function get_limits($type) {
		global $config;
		$this-&gt;filetype = $type;
		switch ($type) {
			case &quot;image&quot;:
				$this-&gt;required_type = explode(&quot;,&quot;, str_replace(&#039; &#039;, &#039;&#039;, $config[&#039;images_ext&#039;]));
				$this-&gt;max_size = $config[&#039;images_max_size&#039;] * 1024;
				$this-&gt;max_x = intval($config[&#039;images_max_x&#039;]);
				$this-&gt;max_y = intval($config[&#039;images_max_y&#039;]);
				$this-&gt;dim_act = intval($config[&#039;images_dim_action&#039;]);
				$this-&gt;tname = &quot;images&quot;;
				$this-&gt;dname = $config[&#039;images_dir&#039;];
				$this-&gt;uname = $config[&#039;images_url&#039;];
				$this-&gt;tcat = 0;
				break;
			case &quot;file&quot;:
				$this-&gt;required_type = explode(&quot;,&quot;, str_replace(&#039; &#039;, &#039;&#039;, $config[&#039;files_ext&#039;]));
				$this-&gt;max_size = $config[&#039;files_max_size&#039;] * 1024;
				$this-&gt;tname = &quot;files&quot;;
				$this-&gt;dname = $config[&#039;files_dir&#039;];
				$this-&gt;uname = $config[&#039;files_url&#039;];
				$this-&gt;tcat = 0;
				break;
			case &quot;avatar&quot;:
				$this-&gt;required_type = explode(&quot;,&quot;, str_replace(&#039; &#039;, &#039;&#039;, $config[&#039;images_ext&#039;]));
				$this-&gt;max_size = $config[&#039;avatar_max_size&#039;] * 1024;
				$this-&gt;tname = &quot;images&quot;;
				$this-&gt;dname = $config[&#039;avatars_dir&#039;];
				$this-&gt;uname = $config[&#039;avatars_url&#039;];
				$this-&gt;tcat = 1;
				break;
			case &quot;photo&quot;:
				$this-&gt;required_type = explode(&quot;,&quot;, str_replace(&#039; &#039;, &#039;&#039;, $config[&#039;images_ext&#039;]));
				$this-&gt;max_size = $config[&#039;photos_max_size&#039;] * 1024;
				$this-&gt;tname = &quot;images&quot;;
				$this-&gt;dname = $config[&#039;photos_dir&#039;];
				$this-&gt;uname = $config[&#039;photos_url&#039;];
				$this-&gt;tcat = 2;
				break;
			default:
				return false;
		}
		return true;
	}
	// fetch selected URL into temp directory
	function file_fetch_url($url) {
		global $lang;
		if ((!($tmpn = tempnam(ini_get(&#039;upload_tmp_dir&#039;), &#039;upload_&#039;))) || (!($f = fopen($tmpn, &#039;w&#039;)))) {
			msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.tempcreate&#039;]));
			return;
		}
		if ($data = @file_get_contents($url)) {
			// Data were read
			fwrite($f, $data);
			fclose($f);
			$filename = end(explode(&quot;/&quot;, $url));
			return array($tmpn, $filename, strlen($data));
		} else {
			// Unable to fetch content (URL)
		}
		return false;
	}
	// * type		- file type (image / file / avatar / photo)
	// * category	- category where to put file
	// * http_var	- name of HTTP variable to transfer file
	// * htt_varnum - number of file that is uploaded in group (via 1 variable)
	// * dsn		- FLAG: store data (files/images) in Data Storage Network (BTREE)
	// *** IS SET:
	//   * linked_ds - id of data storage to link this file
	//   * linked_id - id of item in data stodage to link this file
	// *** IS NOT SET:
	//   * replace	- &#039;replace if present&#039; flag
	//   * randprefix	- add random prefix to file
	//   * randname	- make a random file name
	// * manual		- manual upload mode. File name is sent via &quot;manualfile&quot;
	// *  url			- upload URL instead of file
	// *  manualfile	- file name for manual upload
	// *  manualtmp		- TEMP file where manual uploaded file is [temporally] stored
	// * plugin		- ID of plugin that owns this file
	// * pidentity	- ID of plugin&#039;s identity that owns this file
	// * description- description for image
	// * rpc		- flag: if set, returning result is made in RPC style [ default - not set ]
	function file_upload($param) {
		global $config, $lang, $mysql, $userROW;
		$lang = loadLang(&#039;files&#039;);
		// Normalize category (to make it possible to have empty category)
		$wCategory = ($param[&#039;category&#039;] != &#039;&#039;) ? ($param[&#039;category&#039;] . &#039;/&#039;) : &#039;&#039;;
		//print &quot;CALL file_upload -&gt; upload(&quot;.$param[&#039;http_var&#039;].&quot;//&quot;.$param[&#039;http_varnum&#039;].&quot;)&lt;br&gt;\n&lt;pre&gt;&quot;; var_dump($param); print &quot;&lt;/pre&gt;&lt;br&gt;\n&quot;;
		$http_var = getIsSet($param[&#039;http_var&#039;]);
		$http_varnum = intval(getIsSet($param[&#039;http_varnum&#039;]));
		if ($param[&#039;manual&#039;]) {
			if ($param[&#039;url&#039;]) {
				if (is_array($fetch_result = $this-&gt;file_fetch_url($param[&#039;url&#039;]))) {
					$fname = $param[&#039;manualfile&#039;] ? $param[&#039;manualfile&#039;] : $fetch_result[1];    // override file name if needed
					$ftmp = $fetch_result[0];
					$fsize = filesize($ftmp);
				} else {
					return 0;
				}
			} else {
				$fname = getIsSet($param[&#039;manualfile&#039;]);
				$ftmp = getIsSet($param[&#039;manualtmp&#039;]);
				$fsize = filesize($ftmp);
			}
		} else {
			if ((is_int($http_varnum)) &amp;&amp; is_array($_FILES[$http_var][&#039;name&#039;])) {
				$fname = $_FILES[$http_var][&#039;name&#039;][$http_varnum];
				$fsize = $_FILES[$http_var][&#039;size&#039;][$http_varnum];
				$ftype = $_FILES[$http_var][&#039;type&#039;][$http_varnum];
				$ftmp = $_FILES[$http_var][&#039;tmp_name&#039;][$http_varnum];
				$ferr = $_FILES[$http_var][&#039;error&#039;][$http_varnum];
			} else {
				// in case of one upload we may set a manual filename
				$fname = ($param[&#039;manualfile&#039;]) ? $param[&#039;manualfile&#039;] : $_FILES[$http_var][&#039;name&#039;];
				$fsize = $_FILES[$http_var][&#039;size&#039;];
				$ftype = $_FILES[$http_var][&#039;type&#039;];
				$ftmp = $_FILES[$http_var][&#039;tmp_name&#039;];
				$ferr = $_FILES[$http_var][&#039;error&#039;];
			}
		}
		// Check limits
		if (!$this-&gt;get_limits($param[&#039;type&#039;])) {
			if ($param[&#039;rpc&#039;]) {
				return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 301, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, str_replace(&#039;{fname}&#039;, $fname, $lang[&#039;upload.error.type&#039;])));
			} else {
				msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{fname}&#039;, $fname, $lang[&#039;upload.error.type&#039;])));
				return 0;
			}
		}
		//print &quot;PROCESS: fname=&quot;.$fname.&quot;&lt;br&gt; fsize=&quot;.$fsize.&quot;&lt;br&gt;ftype=&quot;.$ftype.&quot;&lt;br&gt;ftmp=&quot;.$ftmp.&quot;&lt;br&gt;ferr=&quot;.$ferr.&quot;&lt;br&gt;this-&gt;dname=&quot;.$this-&gt;dname.&quot;&lt;br/&gt;\n&quot;;
		//print &quot;Param: &lt;pre&gt;&quot;; var_dump($_FILES); print &quot;&lt;/pre&gt;&lt;br&gt;\n&quot;;
		// * File size
		if ($fsize &gt; $this-&gt;max_size) {
			if ($param[&#039;rpc&#039;]) {
				return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 302, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, str_replace(&#039;{fname}&#039;, $fname, $lang[&#039;upload.error.size&#039;])), &#039;errorDescription&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, str_replace(&#039;{size}&#039;, Formatsize($this-&gt;max_size), $lang[&#039;upload.error.size#info&#039;])));
			} else {
				msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{fname}&#039;, $fname, $lang[&#039;upload.error.size&#039;]), &quot;info&quot; =&gt; str_replace(&#039;{size}&#039;, Formatsize($this-&gt;max_size), $lang[&#039;upload.error.size#info&#039;])));
				return 0;
			}
		}
		// Check for existance of temp file
		if (!$ftmp || !file_exists($ftmp)) {
			if (getIsSet($param[&#039;rpc&#039;])) {
				return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 303, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, var_export($_FILES, true) . str_replace(&#039;{fname}&#039;, $fname, $lang[&#039;upload.error.losttemp&#039;])));
			} else {
				msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{fname}&#039;, $fname, $lang[&#039;upload.error.losttemp&#039;])));
				return 0;
			}
		}
		// ** IMAGES :: Check maximum image size &amp; resize if needed
		if ($param[&#039;type&#039;] == &#039;image&#039;) {
			$im = new image_managment();
			$s = $im-&gt;get_size($ftmp);
			if (!is_array($s)) {
				if ($param[&#039;rpc&#039;]) {
					return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 301, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, str_replace(&#039;{fname}&#039;, $fname, $lang[&#039;upload.error.type&#039;])));
				} else {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{fname}&#039;, $fname, $lang[&#039;upload.error.type&#039;])));
					return 0;
				}
			}
			// Check size
			if ((($this-&gt;max_x &gt; 0) &amp;&amp; ($s[1] &gt; $this-&gt;max_x)) || (($this-&gt;max_y &gt; 0) &amp;&amp; ($s[2] &gt; $this-&gt;max_y))) {
				// !! OVERSIZED !!
				if (!$this-&gt;dim_act) {
					// REJECT
					if ($param[&#039;rpc&#039;]) {
						return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 317, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, str_replace(array(&#039;{fname}&#039;, &#039;{maxx}&#039;, &#039;{maxy}&#039;), array($fname, $this-&gt;max_x, $this-&gt;max_y), $lang[&#039;upload.error.imgsize&#039;])));
					} else {
						msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{fname}&#039;, $fname, $lang[&#039;upload.error.imgsize&#039;])));
						return 0;
					}
				}
				// Try to resize
				$resizeResult = $im-&gt;image_transform(array(&#039;rpc&#039; =&gt; $param[&#039;rpc&#039;], &#039;image&#039; =&gt; $ftmp, &#039;resize&#039; =&gt; array(&#039;x&#039; =&gt; $this-&gt;max_x, &#039;y&#039; =&gt; $this-&gt;max_y)));
				//return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 999, &#039;errorText&#039; =&gt; &quot;X/MAXX::&quot;.$s[1].&quot;/&quot;.$this-&gt;max_x.&quot;, Y/MAXY:&quot;.$s[2].&quot;/&quot;.$this-&gt;max_y.&quot; NX/NY:&quot;.$resizeResult[&#039;data&#039;][&#039;x&#039;].&quot;/&quot;.$resizeResult[&#039;data&#039;][&#039;y&#039;]);
				// Check results
				// ** RPC
				if ($param[&#039;rpc&#039;] &amp;&amp; ((!is_array($resizeResult)) || (!$resizeResult[&#039;status&#039;]))) {
					return $resizeResult;
				}
				// ** Normal call
				if (!is_array($resizeResult)) {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{fname}&#039;, $fname, $lang[&#039;upload.error.imgsize&#039;])));
					return;
				}
			}
		}
		// Process file name
		if ($param[&#039;rpc&#039;]) {
			$fname = iconv(&#039;UTF-8&#039;, &#039;Windows-1251&#039;, $fname);
			//echo &#039;FConv: &#039;.iconv(&#039;UTF-8&#039;, &#039;Windows-1251&#039;, $fil);
		}
		$fil = explode(&quot;.&quot;, strtolower($fname));
		$ext = count($fil) ? array_pop($fil) : &#039;&#039;;
		// * File type [ don&#039;t allow to upload PHP files in any case ]
		if ((array_search(strtolower($ext), $this-&gt;required_type) === false) || (array_search(strtolower($ext), array(&#039;php&#039;, &#039;pht&#039;, &#039;phtml&#039;, &#039;php3&#039;, &#039;php4&#039;, &#039;php5&#039;)) !== false)) {
			if ($param[&#039;rpc&#039;]) {
				return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 304, &#039;errorText&#039; =&gt; str_replace(&#039;{fname}&#039;, $fname, iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.ext&#039;])), &#039;errorDescription&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, str_replace(&#039;{ext}&#039;, join(&quot;, &quot;, $this-&gt;required_type), $lang[&#039;upload.error.ext#info&#039;])));
			} else {
				msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{fname}&#039;, $fname, $lang[&#039;upload.error.ext&#039;]), &quot;info&quot; =&gt; str_replace(&#039;{ext}&#039;, join(&quot;,&quot;, $this-&gt;required_type), $lang[&#039;upload.error.ext#info&#039;])));
				return 0;
			}
		}
		// Manage multiple extensions
		if (!$config[&#039;allow_multiext&#039;]) {
			$fil = array(join(&quot;_&quot;, $fil));
		}
		$parse = new parse();
		$fil = trim(str_replace(array(&#039; &#039;, &#039;\\&#039;, &#039;/&#039;, chr(0)), array(&#039;_&#039;, &#039;&#039;), join(&quot;.&quot;, $fil)));
		$fil = $parse-&gt;translit($fil);
		$fname = $fil . ($ext ? &#039;.&#039; . $ext : &#039;&#039;);
		// Save original file name
		$origFname = $fname;
		// DSN - Data Storage Network. Store data in BTREE if requested
		if ($param[&#039;dsn&#039;]) {
			// Check if directory for DSN exists
			$wDir = $config[&#039;attach_dir&#039;];
			if (!is_dir($wDir)) {
				if ($param[&#039;rpc&#039;]) {
					return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 305, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, str_replace(&#039;{dir}&#039;, $wDir, $lang[&#039;upload.error.dsn&#039;])));
				} else {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; &quot;No access to DSN directory `&quot; . $wDir . &quot;`&quot;));
					return 0;
				}
			}
			// Determine storage tree
			$fn_md5 = md5($fname);
			$dir1 = substr($fn_md5, 0, 2);
			$dir2 = substr($fn_md5, 2, 2);
			$wDir .= &#039;/&#039; . $dir1;
			if (!is_dir($wDir) &amp;&amp; !@mkdir($wDir, 0777)) {
				if ($param[&#039;rpc&#039;]) {
					return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 306, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, str_replace(&#039;{dir}&#039;, $wDir, $lang[&#039;upload.error.dircreate&#039;])));
				} else {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{dir}&#039;, $wDir, $lang[&#039;upload.error.dircreate&#039;])));
					return 0;
				}
			}
			$wDir .= &#039;/&#039; . $dir2;
			if (!is_dir($wDir) &amp;&amp; !@mkdir($wDir, 0777)) {
				if ($param[&#039;rpc&#039;]) {
					return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 307, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, str_replace(&#039;{dir}&#039;, $wDir, $lang[&#039;upload.error.dircreate&#039;])));
				} else {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{dir}&#039;, $wDir, $lang[&#039;upload.error.dircreate&#039;])));
					return 0;
				}
			}
			// Now let&#039;s find empty slot
			$i = 0;
			$xDir = &#039;&#039;;
			while ($i &lt; 999) {
				$i++;
				$xDir = sprintf(&quot;%03u&quot;, $i);
				if (is_dir($wDir . &#039;/&#039; . $xDir)) {
					$xDir = &#039;&#039;;
					continue;
				}
				// Fine. Create this dir ... but check for simultaneous run
				if (!@mkdir($wDir . &#039;/&#039; . $xDir, 0777)) {
					if (is_dir($wDir . &#039;/&#039; . $xDir))
						continue;
					// Unable to create dir
					if ($param[&#039;rpc&#039;]) {
						return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 308, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, str_replace(&#039;{dir}&#039;, $wDir . &#039;/&#039; . $xDir, $lang[&#039;upload.error.dircreate&#039;])));
					} else {
						msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{dir}&#039;, $wDir . &#039;/&#039; . $xDir, $lang[&#039;upload.error.dircreate&#039;])));
						return 0;
					}
				} else {
					break;
				}
			}
			if (!$xDir) {
				if ($param[&#039;rpc&#039;]) {
					return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 309, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, str_replace(&#039;{dir}&#039;, $wDir, $lang[&#039;upload.error.dsn_no_slots&#039;])));
				} else {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{dir}&#039;, $wDir, $lang[&#039;upload.error.dsn_no_slots&#039;])));
					return 0;
				}
			}
			$wDir .= &#039;/&#039; . $xDir;
			// Now let&#039;s upload file
			if ($param[&#039;manual&#039;]) {
				if (!copy($ftmp, $wDir . &#039;/&#039; . $fname)) {
					// Remove empty dir
					rmdir($wDir);
					// Delete file
					unlink($ftmp);
					if ($param[&#039;rpc&#039;]) {
						return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 310, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.move&#039;]));
					} else {
						msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.move&#039;]));
						return 0;
					}
				}
			} else {
				if (!move_uploaded_file($ftmp, $wDir . &#039;/&#039; . $fname)) {
					// Remove empty dir
					rmdir($wDir);
					if ($param[&#039;rpc&#039;]) {
						return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 311, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.move&#039;] . &quot;(&quot; . $ftpm . &quot; =&gt; &quot; . $this-&gt;dname . $wCategory . $fname . &quot;)&quot;));
					} else {
						msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.move&#039;] . &quot;(&quot; . $ftpm . &quot; =&gt; &quot; . $this-&gt;dname . $wCategory . $fname . &quot;)&quot;));
						return 0;
					}
				}
			}
			// Set correct permissions
			chmod($wDir . &#039;/&#039; . $fname, 0644);
			// Create record in SQL DB (or replace old)
			$mysql-&gt;query(&quot;insert into &quot; . prefix . &quot;_&quot; . $this-&gt;tname . &quot; &quot; .
				&quot;(name, storage, orig_name, folder, date, user, owner_id, category, linked_ds, linked_id, plugin, pidentity, description) &quot; .
				&quot;values (&quot; . db_squote($fname) . &quot;, 1,&quot; . db_squote($origFname) . &quot;,&quot; . db_squote($dir1 . &#039;/&#039; . $dir2 . &#039;/&#039; . $xDir) . &quot;, unix_timestamp(now()), &quot; . db_squote($userROW[&#039;name&#039;]) . &quot;,&quot; . db_squote($userROW[&#039;id&#039;]) . &quot;, &quot; . $this-&gt;tcat . &quot;, &quot; . db_squote($param[&#039;linked_ds&#039;]) . &quot;, &quot; . db_squote($param[&#039;linked_id&#039;]) . &quot;, &quot; . db_squote($param[&#039;plugin&#039;]) . &quot;, &quot; . db_squote($param[&#039;pidentity&#039;]) . &quot;, &quot; . db_squote($param[&#039;description&#039;]) . &quot;)&quot;);
			$rowID = $mysql-&gt;record(&quot;select LAST_INSERT_ID() as id&quot;);
			// SQL error
			if (!is_array($rowID)) {
				if ($param[&#039;rpc&#039;]) {
					return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 312, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.sql&#039;]));
				} else {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.sql&#039;]));
					return 0;
				}
			}
			if ($param[&#039;rpc&#039;]) {
				return array(&#039;status&#039; =&gt; 1, &#039;errorCode&#039; =&gt; 0, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.complete&#039;]), &#039;data&#039; =&gt; array(&#039;id&#039; =&gt; $rowID[&#039;id&#039;], &#039;name&#039; =&gt; $fname, &#039;location&#039; =&gt; $dir1 . &#039;/&#039; . $dir2 . &#039;/&#039; . $xDir));
			} else {
				return array($rowID[&#039;id&#039;], $fname, $dir1 . &#039;/&#039; . $dir2 . &#039;/&#039; . $xDir);
			}
		}
		// Create random prefix if requested
		$prefix = &#039;&#039;;
		if ($param[&#039;randprefix&#039;]) {
			$try = 0;
			do {
				$prefix = sprintf(&quot;%04u&quot;, rand(1, 9999));
				$try++;
			} while (($try &lt; 100) &amp;&amp; (file_exists($this-&gt;dname . $wCategory . $prefix . &#039;_&#039; . $fname) || (is_array($row = $mysql-&gt;record(&quot;select * from &quot; . prefix . &quot;_&quot; . $this-&gt;tname . &quot; where name = &quot; . db_squote($prefix . &#039;_&#039; . $fname) . &quot; and folder= &quot; . db_squote($param[&#039;category&#039;]))))));
			if ($try == 100) {
				// Can&#039;t create RAND name - all values are occupied
				if ($param[&#039;rpc&#039;]) {
					return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 313, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.rand&#039;]));
				} else {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.rand&#039;]));
					return 0;
				}
			}
			$fname = $prefix . &#039;_&#039; . $fname;
		}
		$replace_id = 0;
		$row = &#039;&#039;;
		// Now we have correct filename. Let&#039;s check for dups
		if (is_array($row = $mysql-&gt;record(&quot;select * from &quot; . prefix . &quot;_&quot; . $this-&gt;tname . &quot; where name = &quot; . db_squote($fname) . &quot; and folder= &quot; . db_squote($param[&#039;category&#039;]))) || file_exists($this-&gt;dname . $wCategory . $fname)) {
			// Found file. Check if &#039;replace&#039; flag is present and user have enough privilleges
			if ($param[&#039;replace&#039;]) {
				if (!(($row[&#039;user&#039;] == $userROW[&#039;name&#039;]) || ($userROW[&#039;status&#039;] == 1) || ($userROW[&#039;status&#039;] == 2))) {
					if ($param[&#039;rpc&#039;]) {
						return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 314, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.perm.replace&#039;]));
					} else {
						msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.perm.replace&#039;]));
						return 0;
					}
				}
			} else {
				if ($param[&#039;rpc&#039;]) {
					return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 315, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.exists&#039;]), &#039;errorDescription&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.exists#info&#039;]));
				} else {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.exists&#039;], &quot;info&quot; =&gt; $lang[&#039;upload.error.exists#info&#039;]));
					return 0;
				}
			}
			if (is_array($row))
				$replace_id = $row[&#039;id&#039;];
		}
		// We&#039;re ready to move file into target directory
		if (!is_dir($this-&gt;dname . $param[&#039;category&#039;])) {
			// SPECIAL processing for &quot;default&quot; category
			if ($param[&#039;category&#039;] == &#039;default&#039;) {
				@mkdir($this-&gt;dname . $param[&#039;category&#039;], 0777);
				if ($param[&#039;type&#039;] == &#039;image&#039;) {
					@mkdir($this-&gt;dname . $subdirectory . &#039;/thumb&#039;, 0777);
				}
			} else {
				// Category dir doesn&#039;t exists
				if ($param[&#039;rpc&#039;]) {
					return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 316, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, str_replace(&#039;{category}&#039;, $param[&#039;category&#039;], $lang[&#039;upload.error.catnexists&#039;])));
				} else {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{category}&#039;, $param[&#039;category&#039;], $lang[&#039;upload.error.catnexists&#039;])));
					return 0;
				}
			}
		}
		// Now let&#039;s upload file
		if ($param[&#039;manual&#039;]) {
			if (!copy($ftmp, $this-&gt;dname . $wCategory . $fname)) {
				unlink($ftmp);
				if ($param[&#039;rpc&#039;]) {
					return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 310, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.move&#039;]));
				} else {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.move&#039;]));
					return 0;
				}
			}
		} else {
			if (!move_uploaded_file($ftmp, $this-&gt;dname . $wCategory . $fname)) {
				if ($param[&#039;rpc&#039;]) {
					return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 310, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.move&#039;] . &quot;(&quot; . $ftpm . &quot; =&gt; &quot; . $this-&gt;dname . $wCategory . $fname . &quot;)&quot;));
				} else {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.move&#039;] . &quot;(&quot; . $ftpm . &quot; =&gt; &quot; . $this-&gt;dname . $wCategory . $fname . &quot;)&quot;));
					return 0;
				}
			}
		}
		// Set correct permissions
		chmod($this-&gt;dname . $wCategory . $fname, 0644);
		// Create record in SQL DB (or replace old)
		if ($replace_id) {
			// Delete old THUMB (if exists)
			if ($row[&#039;preview&#039;] &amp;&amp; ($param[&#039;type&#039;] == &#039;image&#039;) &amp;&amp; is_file($this-&gt;dname . $param[&#039;category&#039;] . &#039;/thumb/&#039; . $row[&#039;name&#039;])) {
				@unlink($this-&gt;dname . $param[&#039;category&#039;] . &#039;/thumb/&#039; . $row[&#039;name&#039;]);
			}
			$mysql-&gt;query(&quot;update &quot; . prefix . &quot;_&quot; . $this-&gt;tname . &quot; set &quot; .
				&quot;name= &quot; . db_squote($fname) . &quot;, &quot; .
				&quot;folder=&quot; . db_squote($param[&#039;category&#039;]) . &quot;, &quot; .
				&quot;date=unix_timestamp(now()), &quot; .
				&quot;user=&quot; . db_squote($userROW[&#039;name&#039;]) . &quot;, &quot; .
				&quot;owner_id=&quot; . db_squote($userROW[&#039;id&#039;]) .
				(($param[&#039;type&#039;] == &#039;image&#039;) ? &#039;, preview = 0, p_width = 0, p_height = 0&#039; : &#039;&#039;) .
				&quot; where id = &quot; . $replace_id);
			if ($param[&#039;rpc&#039;]) {
				return array(&#039;status&#039; =&gt; 1, &#039;errorCode&#039; =&gt; 0, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.complete&#039;]), &#039;data&#039; =&gt; array(&#039;id&#039; =&gt; $replace_id, &#039;name&#039; =&gt; $fname, &#039;category&#039; =&gt; $wCategory));
			} else {
				return array($replace_id, $fname, $wCategory);
			}
		} else {
			$mysql-&gt;query(&quot;insert into &quot; . prefix . &quot;_&quot; . $this-&gt;tname . &quot; (name, orig_name, folder, date, user, owner_id, category) values (&quot; . db_squote($fname) . &quot;,&quot; . db_squote($origFname) . &quot;,&quot; . db_squote($param[&#039;category&#039;]) . &quot;, unix_timestamp(now()), &quot; . db_squote($userROW[&#039;name&#039;]) . &quot;,&quot; . db_squote($userROW[&#039;id&#039;]) . &quot;, &quot; . $this-&gt;tcat . &quot;)&quot;);
			$rowID = $mysql-&gt;record(&quot;select LAST_INSERT_ID() as id&quot;);
			// SQL error
			if (!is_array($rowID)) {
				if ($param[&#039;rpc&#039;]) {
					return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 312, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.sql&#039;]));
				} else {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.sql&#039;]));
					return 0;
				}
			}
			if ($param[&#039;rpc&#039;]) {
				return array(&#039;status&#039; =&gt; 1, &#039;errorCode&#039; =&gt; 0, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.complete&#039;]), &#039;data&#039; =&gt; array(&#039;id&#039; =&gt; $rowID[&#039;id&#039;], &#039;name&#039; =&gt; $fname, &#039;category&#039; =&gt; $wCategory));
			} else {
				return array($rowID[&#039;id&#039;], $fname, $wCategory);
			}
		}
	}
	// Delete file
	// * type		- file type (image / file / avatar / photo)
	// * category		- category from that file should be deleted
	// * id			- ID of file to delete
	// * name		- filename to delete [if no ID specified]
	function file_delete($param) {
		global $mysql, $lang, $userROW, $config;
		// Check limits
		if (!$this-&gt;get_limits($param[&#039;type&#039;])) {
			msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.type&#039;]));
			return 0;
		}
		// Find file
		if ($param[&#039;id&#039;]) {
			$limit = &quot;id = &quot; . db_squote($param[&#039;id&#039;]);
		} else {
			if (!$param[&#039;category&#039;]) $param[&#039;category&#039;] = &#039;default&#039;;
			$limit = &quot;name = &quot; . db_squote($param[&#039;name&#039;]) . &quot; and folder =&quot; . db_squote($param[&#039;category&#039;]);
		}
		if (is_array($row = $mysql-&gt;record(&quot;select * from &quot; . prefix . &quot;_&quot; . $this-&gt;tname . &quot; where &quot; . $limit))) {
			// Check permissions
			if (!(($row[&#039;owner_id&#039;] == $userROW[&#039;id&#039;]) || ($userROW[&#039;status&#039;] == 1) || ($userROW[&#039;status&#039;] == 2))) {
				msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.perm.delete&#039;]));
				return 0;
			}
			$storageDir = ($row[&#039;storage&#039;] ? $config[&#039;attach_dir&#039;] : $this-&gt;dname) . $row[&#039;folder&#039;];
			// Check if thumb file exists &amp; delete it
			if ($row[&#039;preview&#039;] &amp;&amp; file_exists($storageDir . &#039;/thumb/&#039; . $row[&#039;name&#039;])) {
				if (!@unlink($storageDir . &#039;/thumb/&#039; . $row[&#039;name&#039;])) {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{file}&#039;, $row[&#039;folder&#039;] . &#039;/thumb/&#039; . $row[&#039;name&#039;], $lang[&#039;upload.error.delete&#039;])));
				}
			}
			// Check if file file exists &amp; delete it
			if (file_exists($storageDir . &#039;/&#039; . $row[&#039;name&#039;])) {
				if (!@unlink($storageDir . &#039;/&#039; . $row[&#039;name&#039;])) {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{file}&#039;, $row[&#039;folder&#039;] . &#039;/&#039; . $row[&#039;name&#039;], $lang[&#039;upload.error.delete&#039;])));
					return 0;
				}
				// Now try to delete empty storage directory [ ONLY for DSN ]
				if ($row[&#039;storage&#039;])
					@rmdir($storageDir);
			}
			$mysql-&gt;query(&quot;delete from &quot; . prefix . &quot;_&quot; . $this-&gt;tname . &quot; where id = &quot; . db_squote($row[&#039;id&#039;]));
			return 1;
		} else {
			msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.nofile&#039;] . &quot;, id=&quot; . $param[&#039;id&#039;]));
			return 0;
		}
	}
	// Rename a file within one category
	// * type			- file type (image / file / avatar / photo)
	// * category		- category where to put file
	// * move			- FLAG [ 1 - move mode, 0 - rename mode ]
	// * newcategory	- new category [ TO MOVE FILE ]
	// * id				- ID of file to delete
	// * name			- filename to rename [if no ID specified]
	// * newname		- new filename
	function file_rename($param) {
		global $mysql, $lang, $config, $parse;
		if (defined(&#039;DEBUG&#039;)) {
			print &quot;CALL file_rename(): &lt;pre&gt;&quot;;
			var_dump($param);
			print &quot;&lt;/pre&gt;&lt;br&gt;\n&quot;;
		}
		// Check limits
		if (!$this-&gt;get_limits($param[&#039;type&#039;])) {
			msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.type&#039;]));
			return 0;
		}
		// Find file
		if (!$param[&#039;category&#039;]) $param[&#039;category&#039;] = &#039;default&#039;;
		if ($param[&#039;move&#039;]) {
			if (!$param[&#039;newcategory&#039;]) $param[&#039;newcategory&#039;] = &#039;default&#039;;
		}
		if ($param[&#039;id&#039;]) {
			$limit = &quot;id = &quot; . db_squote($param[&#039;id&#039;]);
		} else {
			$limit = &quot;name = &quot; . db_squote($param[&#039;name&#039;]) . &quot; and folder=&quot; . db_squote($param[&#039;category&#039;]);
		}
		if (is_array($row = $mysql-&gt;record(&quot;select * from &quot; . prefix . &quot;_&quot; . $this-&gt;tname . &quot; where &quot; . $limit))) {
			if ($param[&#039;move&#039;]) {
				if ($param[&#039;newcategory&#039;]) {
					$param[&#039;newcategory&#039;] = trim(str_replace(array(&#039; &#039;, &#039;\\&#039;, &#039;/&#039;, chr(0)), array(&#039;_&#039;, &#039;&#039;), $param[&#039;newcategory&#039;]));
				} else {
					$param[&#039;newcategory&#039;] = &#039;default&#039;;
				}
				if (!$param[&#039;newname&#039;]) $param[&#039;newname&#039;] = $row[&#039;name&#039;];
			}
			$newname = trim(str_replace(array(&#039; &#039;, &#039;\\&#039;, &#039;/&#039;, chr(0)), array(&#039;-&#039;, &#039;&#039;), $param[&#039;newname&#039;]));
			$nnames = explode(&#039;.&#039;, $newname);
			$ext = array_pop($nnames);
			if (array_search($ext, $this-&gt;required_type) === false) {
				msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.ext&#039;], &quot;info&quot; =&gt; str_replace(&#039;{ext}&#039;, join(&quot;,&quot;, $this-&gt;required_type), $lang[&#039;upload.error.ext#info&#039;])));
				return 0;
			}
			$newname = $parse-&gt;translit(implode(&quot;.&quot;, $nnames)) . &quot;.&quot; . $ext;
			// Check for DUP
			if (is_array($mysql-&gt;record(&quot;select * from &quot; . prefix . &quot;_&quot; . $this-&gt;tname . &quot; where folder=&quot; . db_squote($param[&#039;move&#039;] ? $param[&#039;newcategory&#039;] : $row[&#039;folder&#039;]) . &quot; and name=&quot; . db_squote($newname)))) {
				msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.renexists&#039;]));
				return 0;
			}
			// Check if we have enough access and all required directories are created
			if (!is_writable($this-&gt;dname . $row[&#039;folder&#039;] . &#039;/&#039; . $row[&#039;name&#039;])) {
				msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.sysperm.access&#039;]));
				return 0;
			}
			if ($param[&#039;move&#039;] &amp;&amp; !is_dir($this-&gt;dname . $param[&#039;newcategory&#039;])) {
				msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{category}&#039;, $param[&#039;newcategory&#039;], $lang[&#039;upload.error.catnexists&#039;])));
				return 0;
			}
			if ($param[&#039;move&#039;]) {
				// MOVE action
				if (copy($this-&gt;dname . $row[&#039;folder&#039;] . &#039;/&#039; . $row[&#039;name&#039;], $this-&gt;dname . $param[&#039;newcategory&#039;] . &#039;/&#039; . $newname)) {
					unlink($this-&gt;dname . $row[&#039;folder&#039;] . &#039;/&#039; . $row[&#039;name&#039;]);
					$mysql-&gt;query(&quot;update &quot; . prefix . &quot;_&quot; . $this-&gt;tname . &quot; set name=&quot; . db_squote($newname) . &quot;, orig_name=&quot; . db_squote($newname) . &quot;, folder=&quot; . db_squote($param[&#039;newcategory&#039;]) . &quot; where id = &quot; . $row[&#039;id&#039;]);
					if (file_exists($this-&gt;dname . $row[&#039;folder&#039;] . &#039;/thumb/&#039; . $row[&#039;name&#039;])) {
						copy($this-&gt;dname . $row[&#039;folder&#039;] . &#039;/thumb/&#039; . $row[&#039;name&#039;], $this-&gt;dname . $param[&#039;newcategory&#039;] . &#039;/thumb/&#039; . $newname);
						unlink($this-&gt;dname . $row[&#039;folder&#039;] . &#039;/thumb/&#039; . $row[&#039;name&#039;]);
					}
					return 1;
				} else {
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.copy&#039;]));
					return 0;
				}
			} else {
				// RENAME action
				if (rename($this-&gt;dname . $row[&#039;folder&#039;] . &#039;/&#039; . $row[&#039;name&#039;], $this-&gt;dname . $row[&#039;folder&#039;] . &#039;/&#039; . $newname)) {
					msg(array(&quot;text&quot; =&gt; $lang[&#039;upload.renamed&#039;]));
					$mysql-&gt;query(&quot;update &quot; . prefix . &quot;_&quot; . $this-&gt;tname . &quot; set name=&quot; . db_squote($newname) . &quot;, orig_name=&quot; . db_squote($newname) . &quot; where id = &quot; . $row[&#039;id&#039;]);
					if (file_exists($this-&gt;dname . $row[&#039;folder&#039;] . &#039;/thumb/&#039; . $row[&#039;name&#039;])) {
						rename($this-&gt;dname . $row[&#039;folder&#039;] . &#039;/thumb/&#039; . $row[&#039;name&#039;], $this-&gt;dname . $row[&#039;folder&#039;] . &#039;/thumb/&#039; . $newname);
					}
					return 1;
				}
			}
		}
		msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.rename&#039;]));
		return 0;
	}
	// Create new directory/category
	// * type		- file type (image / file / avatar / photo)
	// * category	- category where to put file
	function category_create($type, $category) {
		global $lang, $parse;
		if (($dir = get_item_dir($type)) === false) {
			print &quot;No&quot;;
			return;
		}
		$category = $parse-&gt;translit(trim(str_replace(array(&#039; &#039;, &#039;\\&#039;, &#039;/&#039;, chr(0)), array(&#039;-&#039;, &#039;&#039;), $category)));
		if (is_dir($dir . $category)) {
			msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.catexists&#039;], &quot;info&quot; =&gt; $lang[&#039;upload.error.catexists#info&#039;]));
			return;
		}
		if (@mkdir($dir . $category, 0777) &amp;&amp; (($type != &quot;image&quot;) || @mkdir($dir . $category . &#039;/thumb&#039;, 0777))) {
			msg(array(&quot;text&quot; =&gt; $lang[&#039;upload.catcreated&#039;]));
		} else {
			msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.catcreate&#039;]));
		}
	}
	// Delete a category
	// * type		- file type (image / file / avatar / photo)
	// * category	- category where to put file
	function category_delete($type, $category) {
		global $mysql, $lang;
		if (($dir = get_item_dir($type)) === false) {
			return;
		}
		$category = trim(str_replace(array(&#039; &#039;, &#039;\\&#039;, &#039;/&#039;, chr(0)), array(&#039;_&#039;, &#039;&#039;), $category));
		if ($category &amp;&amp; is_dir($dir . $category)) {
			if ($this-&gt;count_dir($dir . $category)) {
				msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.catnotempty&#039;]));
				return;
			}
			if (is_dir($dir . $category . &#039;/thumb&#039;)) {
				@rmdir($dir . $category . &#039;/thumb&#039;);
			}
			if (@rmdir($dir . $category)) {
				msg(array(&quot;text&quot; =&gt; $lang[&#039;upload.catdeleted&#039;]));
			} else {
				msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{dir}&#039;, $dir . $category, $lang[&#039;upload.error.delcat&#039;])));
			}
			return;
		}
		msg(array(&quot;text&quot; =&gt; $lang[&#039;upload.catdeleted&#039;]));
	}
	function count_dir($dir) {
		if ($d = @opendir($dir)) {
			$cnt = 0;
			while (($file = readdir($d)) !== false)
				if ($file != &#039;.&#039; &amp;&amp; $file != &#039;..&#039; &amp;&amp; is_file($dir . &#039;/&#039; . $file))
					$cnt++;
			closedir($d);
			return $cnt;
		}
		return false;
	}
}
// ======================================================================= //
// Image managment class                                                   //
// ======================================================================= //
class image_managment {
	function image_managment() {
		return;
	}
	// Get image size. Return an array with params:
	// index 0 - image type (same as in getimagesize())
	// index 1 - image width
	// index 2 - image height
	function get_size($fname) {
		if (is_array($info = @getimagesize($fname))) {
			return array($info[2], $info[0], $info[1]);
		}
		return null;
	}
	// Params:
	//	rpc			- flag if we&#039;re called via RPC call
	function create_thumb($dir, $file, $sizeX, $sizeY, $quality = 0, $param = []) {
		global $lang;
		$fname = $dir . &#039;/&#039; . $file;
		//print &quot;CALL create_thumb($dir, $file, $sizeX, $sizeY)&lt;br&gt;\n&quot;;
		// Check if we have a directory for thumb
		if (!is_dir($dir . &#039;/thumb&#039;)) {
			if (!@mkdir($dir . &#039;/thumb&#039;, 0777)) {
				if ($param[&#039;rpc&#039;]) {
					return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 351, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.sysperm.thumbdir&#039;]));
				}
				msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.sysperm.thumbdir&#039;]));
				return false;
			}
		}
		// Check if file exists and we can get it&#039;s image size
		if (!file_exists($fname) || !is_array($sz = @getimagesize($fname))) {
			if ($param[&#039;rpc&#039;]) {
				return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 352, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.open&#039;] . $fname));
			}
			msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.open&#039;]));
			return false;
		}
		$origX = $sz[0];
		$origY = $sz[1];
		$origType = $sz[2];
		if (!(($sizeX &gt; 0) &amp;&amp; ($sizeY &gt; 0) &amp;&amp; ($origX &gt; 0) &amp;&amp; ($origY &gt; 0))) {
			if ($param[&#039;rpc&#039;]) {
				return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 353, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, &#039;Unable to determine image size&#039;));
			}
			return false;
		}
		// Calculate resize factor
		$factor = max($origX / $sizeX, $origY / $sizeY);
		// Don&#039;t enlarge picture without need
		if ($factor &lt; 1) $factor = 1;
		// Check if we can open this type of image and open it
		$cmd = &#039;imagecreatefrom&#039;;
		switch ($origType) {
			case 1:
				$cmd .= &#039;gif&#039;;
				break;
			case 2:
				$cmd .= &#039;jpeg&#039;;
				break;
			case 3:
				$cmd .= &#039;png&#039;;
				break;
			case 6:
				$cmd .= &#039;bmp&#039;;
				break;
			case 18:
			    $cmd .= &#039;webp&#039;;
				break;
		}
		if (!$cmd || !function_exists($cmd)) {
			if ($param[&#039;rpc&#039;]) {
				return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 354, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, str_replace(&#039;{func}&#039;, $cmd, $lang[&#039;upload.error.libformat&#039;])));
			}
			msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{func}&#039;, $cmd, $lang[&#039;upload.error.libformat&#039;])));
			return;
		}
		switch ($origType) {
			case 1:
				$img = @imagecreatefromgif($fname);
				break;
			case 2:
				$img = @imagecreatefromjpeg($fname);
				break;
			case 3:
				$img = @imagecreatefrompng($fname);
				break;
			case 6:
				$img = @imagecreatefrombmp($fname);
				break;
			case 18:
				$img = @imagecreatefromwebp($fname);
				break;
		}
		if (!$img) {
			if ($param[&#039;rpc&#039;]) {
				return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 355, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.open&#039;]));
			}
			msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.open&#039;]));
			return false;
		}
		// Calculate thumb size and create an empty object for it
		$newX = round($origX / $factor);
		$newY = round($origY / $factor);
		$newimg = imagecreatetruecolor($newX, $newY);
		// Prepare for transparency // NON-ALPHA transparency
		$oTColor = imagecolortransparent($img);
		if ($oTColor &gt;= 0 &amp;&amp; $oTColor &lt; imagecolorstotal($img)) {
			$TColor = imagecolorsforindex($img, $oTColor);
			$nTColor = imagecolorallocate($newimg, $TColor[&#039;red&#039;], $TColor[&#039;green&#039;], $TColor[&#039;blue&#039;]);
			imagefill($newimg, 0, 0, $nTColor);
			imagecolortransparent($newimg, $nTColor);
		} else {
			// Check for ALPHA transparency in PNG
			if ($origType == 3) {
				imagealphablending($newimg, false);
				$nTColor = imagecolorallocatealpha($newimg, 0, 0, 0, 127);
				imagefill($newimg, 0, 0, $nTColor);
				imagesavealpha($newimg, true);
			}
		}
		// Resize image
		imagecopyresampled($newimg, $img, 0, 0, 0, 0, $newX, $newY, $origX, $origY);
		// Try to write resized image
		switch ($origType) {
			case 1:
				$res = @imagegif($newimg, $dir . &#039;/thumb/&#039; . $file);
				break;
			case 2:
				$res = @imagejpeg($newimg, $dir . &#039;/thumb/&#039; . $file, ($quality &gt;= 10 &amp;&amp; $quality &lt;= 100) ? $quality : 80);
				break;
			case 3:
				$res = @imagepng($newimg, $dir . &#039;/thumb/&#039; . $file);
				break;
			case 6:
				$res = @imagebmp($newimg, $dir . &#039;/thumb/&#039; . $file);
				break;
			case 18:
				$res = @imagewebp($newimg, $dir . &#039;/thumb/&#039; . $file, ($quality &gt;= 10 &amp;&amp; $quality &lt;= 100) ? $quality : 80);
				break;
		}
		// Set correct permissions to file
		@chmod($dir . &#039;/thumb/&#039; . $file, 0644);
		if (!$res) {
			if ($param[&#039;rpc&#039;]) {
				return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 356, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.thumbcreate&#039;]));
			}
			msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.thumbcreate&#039;]));
			return false;
		}
		if ($param[&#039;rpc&#039;]) {
			return array(&#039;status&#039; =&gt; 1, &#039;errorCode&#039; =&gt; 0, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.complete&#039;]), &#039;data&#039; =&gt; array(&#039;x&#039; =&gt; $newX, &#039;y&#039; =&gt; $newY));
		}
		return array($newX, $newY);
	}
	// Transformate original image
	// * image			- filename of original image
	// * stamp			- FLAG if we need to add a stamp
	// * resize			- Array for image resize
	// ** x					- size X
	// ** y					- size Y
	// ** stampfile		- filename of stamp file
	// ** stamp_transparency - %% of transparency of added stamp [ default: 40 ]
	// ** stamp_noerror	- don&#039;t generate an error if it was not possible to add stamp
	// * shadow			- FLAG if we need to add a shadow
	// * outquality		- with what quality we should write resulting file (for JPEG) [ default: 80 ]
	// * outfile		- filename to write a result [ default: original file ]
	// * rpc			- flag shows if call is made via RPC call
	function image_transform($param) {
		//function add_stamp($image, $stamp, $transparency = 40, $quality = 80){
		global $config, $lang;
		// LOAD ORIGINAL IMAGE
		// Check if file exists and we can get it&#039;s image size
		if (!file_exists($param[&#039;image&#039;]) || !is_array($sz = @getimagesize($param[&#039;image&#039;]))) {
			if ($param[&#039;rpc&#039;]) {
				return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 401, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.open&#039;] . &#039; &#039; . $param[&#039;image&#039;]));
			}
			msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.open&#039;]));
			return 0;
		}
		$origX = $sz[0];
		$origY = $sz[1];
		$origType = $sz[2];
		// Check if we can open this type of image and open it
		$cmd = &#039;imagecreatefrom&#039;;
		switch ($origType) {
			case 1:
				$cmd .= &#039;gif&#039;;
				break;
			case 2:
				$cmd .= &#039;jpeg&#039;;
				break;
			case 3:
				$cmd .= &#039;png&#039;;
				break;
			case 6:
				$cmd .= &#039;bmp&#039;;
				break;
			case 18:
				$cmd .= &#039;webp&#039;;
				break;
		}
		if (!$cmd || !function_exists($cmd)) {
			if ($param[&#039;rpc&#039;]) {
				return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 402, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, str_replace(&#039;{func}&#039;, $cmd, $lang[&#039;upload.error.libformat&#039;])));
			}
			msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{func}&#039;, $cmd, $lang[&#039;upload.error.libformat&#039;])));
			return;
		}
		switch ($origType) {
			case 1:
				$img = @imagecreatefromgif($param[&#039;image&#039;]);
				break;
			case 2:
				$img = @imagecreatefromjpeg($param[&#039;image&#039;]);
				break;
			case 3:
				$img = @imagecreatefrompng($param[&#039;image&#039;]);
				break;
			case 6:
				$img = @imagecreatefrombmp($param[&#039;image&#039;]);
				break;
			case 18:
				$img = @imagecreatefromwebp($param[&#039;image&#039;]);
				break;
		}
		if (!$img) {
			if ($param[&#039;rpc&#039;]) {
				return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 403, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.open&#039;]));
			}
			msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.open&#039;]));
			return;
		}
		// Check if resize of original file is requested
		if (isset($param[&#039;resize&#039;]) &amp;&amp; is_array($param[&#039;resize&#039;]) &amp;&amp; ($param[&#039;resize&#039;][&#039;x&#039;] &gt; 0) &amp;&amp; ($param[&#039;resize&#039;][&#039;y&#039;] &gt; 0)) {
			// Calculate ratio and new X/Y sizes
			$ratio = min($param[&#039;resize&#039;][&#039;x&#039;] / $origX, $param[&#039;resize&#039;][&#039;y&#039;] / $origY);
			$newX = round($origX * $ratio);
			$newY = round($origY * $ratio);
			// Create image area
			$newImg = imagecreatetruecolor($newX, $newY);
			// Preserver transparency
			if (($origType == 1) || ($origType == 3)) {
				imagecolortransparent($newImg, imagecolorallocatealpha($newImg, 0, 0, 0, 127));
				imagealphablending($newImg, false);
				imagesavealpha($newImg, true);
			}
			// Resize image
			imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newX, $newY, $origX, $origY);
			// Save new information into current image
			$img = $newImg;
			$origX = $newX;
			$origY = $newY;
		}
		if ($param[&#039;stamp&#039;]) {
			// LOAD STAMP IMAGE
			if (!file_exists($param[&#039;stampfile&#039;]) || !is_array($sz = @getimagesize($param[&#039;stampfile&#039;]))) {
				if (!$param[&#039;stamp_noerror&#039;]) {
					if ($param[&#039;rpc&#039;]) {
						return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 404, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.openstamp&#039;]));
					}
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.openstamp&#039;]));
				}
				return 0;
			}
			$stampX = $sz[0];
			$stampY = $sz[1];
			$stampType = $sz[2];
			// Check if we can open this type of image and open it
			$cmd = &#039;imagecreatefrom&#039;;
			switch ($origType) {
				case 1:
					$cmd .= &#039;gif&#039;;
					break;
				case 2:
					$cmd .= &#039;jpeg&#039;;
					break;
				case 3:
					$cmd .= &#039;png&#039;;
					break;
				case 6:
					$cmd .= &#039;bmp&#039;;
					break;
				case 18:
					$cmd .= &#039;webp&#039;;
					break;
			}
			if (!$cmd || !function_exists($cmd)) {
				if ($param[&#039;rpc&#039;]) {
					return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 402, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, str_replace(&#039;{func}&#039;, $cmd, $lang[&#039;upload.error.libformat&#039;])));
				}
				msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; str_replace(&#039;{func}&#039;, $cmd, $lang[&#039;upload.error.libformat&#039;])));
				return;
			}
			switch ($stampType) {
				case 1:
					$stamp = @imagecreatefromgif($param[&#039;stampfile&#039;]);
					break;
				case 2:
					$stamp = @imagecreatefromjpeg($param[&#039;stampfile&#039;]);
					break;
				case 3:
					$stamp = @imagecreatefrompng($param[&#039;stampfile&#039;]);
					break;
				case 6:
					$stamp = @imagecreatefrombmp($param[&#039;stampfile&#039;]);
					break;
				case 18:
					$stamp = @imagecreatefromwebp($param[&#039;stampfile&#039;]);
					break;
			}
			if (!$stamp) {
				if (!$param[&#039;stamp_noerror&#039;]) {
					if ($param[&#039;rpc&#039;]) {
						return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 405, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.openstamp&#039;]));
					}
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.openstamp&#039;]));
				}
				return;
			}
			// BOTH FILES ARE LOADED
			$destX = $origX - $stampX - 10;
			$destY = $origY - $stampY - 10;
			if (($destX &lt; 0) || ($destY &lt; 0)) {
				if (!$param[&#039;stamp_noerror&#039;]) {
					if ($param[&#039;rpc&#039;]) {
						return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 406, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.stampsize&#039;]));
					}
					msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.stampsize&#039;]));
				}
				return;
			}
			if (($param[&#039;stamp_transparency&#039;] &lt; 1) || ($param[&#039;stamp_transparency&#039;] &gt; 100)) {
				$param[&#039;stamp_transparency&#039;] = 40;
			}
			if ($stampType == 3)
				$this-&gt;imagecopymerge_alpha($img, $stamp, $destX, $destY, 0, 0, $stampX, $stampY, $param[&#039;stamp_transparency&#039;]);
			else
				imageCopyMerge($img, $stamp, $destX, $destY, 0, 0, $stampX, $stampY, $param[&#039;stamp_transparency&#039;]);
		}
		$newX = $origX;
		$newY = $origY;
		if ($param[&#039;shadow&#039;]) {
			$newX = $origX + 5;
			$newY = $origY + 5;
			$newimg = imagecreatetruecolor($newX, $newY);
			$background = array(&quot;r&quot; =&gt; 255, &quot;g&quot; =&gt; 255, &quot;b&quot; =&gt; 255);
			$step_offset = array(&quot;r&quot; =&gt; ($background[&quot;r&quot;] / 10), &quot;g&quot; =&gt; ($background[&quot;g&quot;] / 10), &quot;b&quot; =&gt; ($background[&quot;b&quot;] / 10));
			$current_color = $background;
			for ($i = 0; $i &lt;= 5; $i++) {
				$colors[$i] = @imagecolorallocate($newimg, round($current_color[&quot;r&quot;]), round($current_color[&quot;g&quot;]), round($current_color[&quot;b&quot;]));
				$current_color[&quot;r&quot;] -= $step_offset[&quot;r&quot;];
				$current_color[&quot;g&quot;] -= $step_offset[&quot;g&quot;];
				$current_color[&quot;b&quot;] -= $step_offset[&quot;b&quot;];
			}
			imagefilledrectangle($newimg, 0, 0, $newX, $newY, $colors[0]);
			for ($i = 0; $i &lt;= 5; $i++) {
				@imagefilledrectangle($newimg, 5, 5, $newX - $i, $newY - $i, $colors[$i]);
			}
			imagecopymerge($newimg, $img, 0, 0, 0, 0, $origX, $origY, 100);
			$img = $newimg;
		}
		// WRITE A RESULT FILE
		if (($param[&#039;outquality&#039;] &lt; 10) || ($param[&#039;outquality&#039;] &gt; 100)) {
			$param[&#039;outquality&#039;] = 80;
		}
		if (!$param[&#039;outfile&#039;]) $param[&#039;outfile&#039;] = $param[&#039;image&#039;];
		switch ($origType) {
			case 1:
				$res = @imagegif($img, $param[&#039;outfile&#039;]);
				break;
			case 2:
				$res = @imagejpeg($img, $param[&#039;outfile&#039;], $param[&#039;outquality&#039;]);
				break;
			case 3:
				$res = @imagepng($img, $param[&#039;outfile&#039;]);
				break;
			case 6:
				$res = @imagebmp($img, $param[&#039;outfile&#039;]);
				break;
			case 18:
				$res = @imagewebp($img, $param[&#039;outfile&#039;], $param[&#039;outquality&#039;]);
				break;
		}
		if (!$res) {
			if ($param[&#039;rpc&#039;]) {
				return array(&#039;status&#039; =&gt; 0, &#039;errorCode&#039; =&gt; 407, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.error.addstamp&#039;]));
			}
			msg(array(&quot;type&quot; =&gt; &quot;error&quot;, &quot;text&quot; =&gt; $lang[&#039;upload.error.addstamp&#039;]));
			return;
		}
		if ($param[&#039;rpc&#039;]) {
			return array(&#039;status&#039; =&gt; 1, &#039;errorCode&#039; =&gt; 0, &#039;errorText&#039; =&gt; iconv(&#039;Windows-1251&#039;, &#039;UTF-8&#039;, $lang[&#039;upload.complete&#039;]), &#039;data&#039; =&gt; array(&#039;x&#039; =&gt; $newX, &#039;y&#039; =&gt; $newY));
		}
		return array($newX, $newY);
	}
	function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct) {
		if (!isset($pct)) {
			return false;
		}
		$pct /= 100;
		// Get image width and height
		$w = imagesx($src_im);
		$h = imagesy($src_im);
		// Turn alpha blending off
		imagealphablending($src_im, false);
		// Find the most opaque pixel in the image (the one with the smallest alpha value)
		$minalpha = 127;
		for ($x = 0; $x &lt; $w; $x++)
			for ($y = 0; $y &lt; $h; $y++) {
				$alpha = (imagecolorat($src_im, $x, $y) &gt;&gt; 24) &amp; 0xFF;
				if ($alpha &lt; $minalpha) {
					$minalpha = $alpha;
				}
			}
		//loop through image pixels and modify alpha for each
		for ($x = 0; $x &lt; $w; $x++) {
			for ($y = 0; $y &lt; $h; $y++) {
				//get current alpha value (represents the TANSPARENCY!)
				$colorxy = imagecolorat($src_im, $x, $y);
				$alpha = ($colorxy &gt;&gt; 24) &amp; 0xFF;
				//calculate new alpha
				if ($minalpha !== 127) {
					$alpha = 127 + 127 * $pct * ($alpha - 127) / (127 - $minalpha);
				} else {
					$alpha += 127 * $pct;
				}
				//get the color index with new alpha
				$alphacolorxy = imagecolorallocatealpha($src_im, ($colorxy &gt;&gt; 16) &amp; 0xFF, ($colorxy &gt;&gt; 8) &amp; 0xFF, $colorxy &amp; 0xFF, $alpha);
				//set pixel with the new color + opacity
				if (!imagesetpixel($src_im, $x, $y, $alphacolorxy)) {
					return false;
				}
			}
		}
		// The image copy
		imagecopy($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
	}
}</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (irbees2008)]]></author>
			<pubDate>Tue, 28 Jan 2020 12:08:07 +0000</pubDate>
			<guid>https://ngcms.ru/forum/viewtopic.php?pid=45058#p45058</guid>
		</item>
		<item>
			<title><![CDATA[Re: xfilds Не поддерживает формат webp]]></title>
			<link>https://ngcms.ru/forum/viewtopic.php?pid=45052#p45052</link>
			<description><![CDATA[<p>Ну да, не работает. Файл <a href="/forum/go.php?link=https://github.com/irbees2008/ngcms-core/blob/master/engine/includes/classes/upload.class.php" rel="nofollow">https://github.com/irbees2008/ngcms-cor … .class.php</a> нужно заменить на хосте.</p>]]></description>
			<author><![CDATA[dummy@example.com (rusiq)]]></author>
			<pubDate>Tue, 28 Jan 2020 10:09:28 +0000</pubDate>
			<guid>https://ngcms.ru/forum/viewtopic.php?pid=45052#p45052</guid>
		</item>
		<item>
			<title><![CDATA[Re: xfilds Не поддерживает формат webp]]></title>
			<link>https://ngcms.ru/forum/viewtopic.php?pid=45051#p45051</link>
			<description><![CDATA[<p>можешь глянуть все тоже самое https://o-kredite.info/engine/admin.php</p>]]></description>
			<author><![CDATA[dummy@example.com (irbees2008)]]></author>
			<pubDate>Tue, 28 Jan 2020 10:03:44 +0000</pubDate>
			<guid>https://ngcms.ru/forum/viewtopic.php?pid=45051#p45051</guid>
		</item>
		<item>
			<title><![CDATA[Re: xfilds Не поддерживает формат webp]]></title>
			<link>https://ngcms.ru/forum/viewtopic.php?pid=45050#p45050</link>
			<description><![CDATA[<p>пробывал, все также, что за хрень не пойму</p>]]></description>
			<author><![CDATA[dummy@example.com (irbees2008)]]></author>
			<pubDate>Tue, 28 Jan 2020 10:00:31 +0000</pubDate>
			<guid>https://ngcms.ru/forum/viewtopic.php?pid=45050#p45050</guid>
		</item>
		<item>
			<title><![CDATA[Re: xfilds Не поддерживает формат webp]]></title>
			<link>https://ngcms.ru/forum/viewtopic.php?pid=45049#p45049</link>
			<description><![CDATA[<p>7.2.2</p>]]></description>
			<author><![CDATA[dummy@example.com (rusiq)]]></author>
			<pubDate>Tue, 28 Jan 2020 09:55:53 +0000</pubDate>
			<guid>https://ngcms.ru/forum/viewtopic.php?pid=45049#p45049</guid>
		</item>
		<item>
			<title><![CDATA[Re: xfilds Не поддерживает формат webp]]></title>
			<link>https://ngcms.ru/forum/viewtopic.php?pid=45048#p45048</link>
			<description><![CDATA[<p>Версия php какая</p>]]></description>
			<author><![CDATA[dummy@example.com (irbees2008)]]></author>
			<pubDate>Tue, 28 Jan 2020 09:54:21 +0000</pubDate>
			<guid>https://ngcms.ru/forum/viewtopic.php?pid=45048#p45048</guid>
		</item>
		<item>
			<title><![CDATA[Re: xfilds Не поддерживает формат webp]]></title>
			<link>https://ngcms.ru/forum/viewtopic.php?pid=45047#p45047</link>
			<description><![CDATA[<p>Все отлично работает.</p>]]></description>
			<author><![CDATA[dummy@example.com (rusiq)]]></author>
			<pubDate>Tue, 28 Jan 2020 09:49:59 +0000</pubDate>
			<guid>https://ngcms.ru/forum/viewtopic.php?pid=45047#p45047</guid>
		</item>
		<item>
			<title><![CDATA[Re: xfilds Не поддерживает формат webp]]></title>
			<link>https://ngcms.ru/forum/viewtopic.php?pid=45046#p45046</link>
			<description><![CDATA[<p>win. ссылка превью выдает ошибку 404</p>]]></description>
			<author><![CDATA[dummy@example.com (irbees2008)]]></author>
			<pubDate>Tue, 28 Jan 2020 09:47:34 +0000</pubDate>
			<guid>https://ngcms.ru/forum/viewtopic.php?pid=45046#p45046</guid>
		</item>
		<item>
			<title><![CDATA[Re: xfilds Не поддерживает формат webp]]></title>
			<link>https://ngcms.ru/forum/viewtopic.php?pid=45045#p45045</link>
			<description><![CDATA[<p>Качну https://github.com/irbees2008/ngcms-core, пощелкаю, отпишусь. Там какая кодировка?</p>]]></description>
			<author><![CDATA[dummy@example.com (rusiq)]]></author>
			<pubDate>Tue, 28 Jan 2020 09:43:06 +0000</pubDate>
			<guid>https://ngcms.ru/forum/viewtopic.php?pid=45045#p45045</guid>
		</item>
		<item>
			<title><![CDATA[Re: xfilds Не поддерживает формат webp]]></title>
			<link>https://ngcms.ru/forum/viewtopic.php?pid=45043#p45043</link>
			<description><![CDATA[<p>превью та нет</p>]]></description>
			<author><![CDATA[dummy@example.com (irbees2008)]]></author>
			<pubDate>Tue, 28 Jan 2020 09:37:37 +0000</pubDate>
			<guid>https://ngcms.ru/forum/viewtopic.php?pid=45043#p45043</guid>
		</item>
		<item>
			<title><![CDATA[Re: xfilds Не поддерживает формат webp]]></title>
			<link>https://ngcms.ru/forum/viewtopic.php?pid=45042#p45042</link>
			<description><![CDATA[<p>То есть получается, что проблема с форматом webp решена?</p>]]></description>
			<author><![CDATA[dummy@example.com (rusiq)]]></author>
			<pubDate>Tue, 28 Jan 2020 09:33:53 +0000</pubDate>
			<guid>https://ngcms.ru/forum/viewtopic.php?pid=45042#p45042</guid>
		</item>
	</channel>
</rss>
