<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sb0y[AT]home &#187; Программирование</title>
	<atom:link href="http://www.bagrincev.ru/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bagrincev.ru</link>
	<description>Уютный бложик девелопера.</description>
	<lastBuildDate>Fri, 30 Jul 2010 13:23:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>bash-&gt;установка бита владельца директории из списка</title>
		<link>http://www.bagrincev.ru/bash-set-uids-from-list/</link>
		<comments>http://www.bagrincev.ru/bash-set-uids-from-list/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 22:05:17 +0000</pubDate>
		<dc:creator>Sb0y</dc:creator>
				<category><![CDATA[Программирование]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[динамические права]]></category>
		<category><![CDATA[список]]></category>
		<category><![CDATA[текст]]></category>

		<guid isPermaLink="false">http://www.bagrincev.ru/?p=976</guid>
		<description><![CDATA[Недавно пришлось решать немного странную задачку на BASH. Был список в текстовом формате: группа=путь Нужно было пройтись по каждому элементу списка и установить группу указанного в нём же. На сервере стоял старый BASH, ассоциативных массивов, в котором ещё небыло. Написал вот это: #!/bin/bash &#160; if &#91; &#34;$1&#34; == &#34;--help&#34; &#93; &#124;&#124; &#91; &#34;$1&#34; == &#34;help&#34; ]]></description>
			<content:encoded><![CDATA[<p>Недавно пришлось решать немного странную задачку на BASH. Был список в текстовом формате:</p>
<pre>
группа=путь
</pre>
<p>Нужно было пройтись по каждому элементу списка и установить группу указанного в нём же.<br />
На сервере стоял старый BASH, ассоциативных массивов, в котором ещё небыло.<br />
<span id="more-976"></span><br />
Написал вот это:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$1&quot;</span> == <span style="color: #ff0000;">&quot;--help&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$1&quot;</span> == <span style="color: #ff0000;">&quot;help&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Использование: &lt;имя скрипта&gt; &lt;путь до списка&gt; &lt;путь до лог-файла&gt; Все параметры не обязательны. Если скрипт не получит путь до файла-списка - попытается открыть файл 'list' в своей директории. Тоже самое касается лог-файла.&quot;</span>;
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$2&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #007800;">log</span>=<span style="color: #ff0000;">&quot;log.txt&quot;</span>;
<span style="color: #000000; font-weight: bold;">else</span>
	<span style="color: #007800;">log</span>=$<span style="color: #000000;">2</span>;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
mess <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
&nbsp;
	<span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">date</span></span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>D-<span style="color: #000000; font-weight: bold;">%</span>r<span style="color: #000000; font-weight: bold;">`</span>;
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[ <span style="color: #007800;">$date</span>] $1&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span>;
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[ <span style="color: #007800;">$date</span>] $1&quot;</span>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$2&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>;
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-w</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$log</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>;
<span style="color: #000000; font-weight: bold;">else</span>
	mess <span style="color: #ff0000;">&quot;Лог-файл не доступен для записи.&quot;</span> <span style="color: #000000;">0</span>;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #007800;">l</span>=<span style="color: #ff0000;">&quot;list&quot;</span>;
<span style="color: #000000; font-weight: bold;">else</span>
	<span style="color: #007800;">l</span>=$<span style="color: #000000;">1</span>;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">list</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$l</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$list</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	mess <span style="color: #ff0000;">&quot;Ошибка при открытии файла-списка!&quot;</span> <span style="color: #000000;">1</span>;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$list</span>;
<span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #007800;">group</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$i</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;=&quot;</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">dir</span></span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$i</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;=&quot;</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">chgrp</span> <span style="color: #660033;">-R</span> <span style="color: #007800;">$group</span> <span style="color: #007800;">$dir</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		mess <span style="color: #ff0000;">&quot;Установлена группа '<span style="color: #007800;">$group</span>' для дир. '<span style="color: #007800;">$dir</span>'&quot;</span> <span style="color: #000000;">0</span>;
	<span style="color: #000000; font-weight: bold;">else</span>
		mess <span style="color: #ff0000;">&quot;Ошибка при обработке дир. '<span style="color: #007800;">$dir</span>'&quot;</span> <span style="color: #000000;">0</span>;
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>Скрипт по умолчанию считывает текстовый файл &laquo;list&raquo;, лежащий рядом, в его директории. Если есть потребность указать файл из другой директории, вызывайте скрипт так:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">script <span style="color: #000000; font-weight: bold;">&lt;</span>путь-до-файл-листа<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>путь-до-лог-файла<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Ещё можно посмотреть help-сообщение, командой <strong>script &#8211;help</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bagrincev.ru/bash-set-uids-from-list/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JavaScript: текст внутри полей, при фокусе и выходе из него</title>
		<link>http://www.bagrincev.ru/javascript-text-inside-input-boxes-onblur-and-onfocus/</link>
		<comments>http://www.bagrincev.ru/javascript-text-inside-input-boxes-onblur-and-onfocus/#comments</comments>
		<pubDate>Sun, 02 May 2010 15:09:47 +0000</pubDate>
		<dc:creator>Sb0y</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[Программирование]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.bagrincev.ru/?p=931</guid>
		<description><![CDATA[Эта штука часто используется в формах быстрого поиска. Иногда замечаю, что на сайтах либо убирают событие onblur, чтобы по нажатию на кнопку submit, поле не потеряло значение и в поиск не ушла пустая строка, ну и другие не красивые решения, на скорую руку. Для себя я навалял &#171;умную&#187; функцию, которая всегда &#171;знает&#187; как себя правильно ]]></description>
			<content:encoded><![CDATA[<p>Эта штука часто используется в формах быстрого поиска. Иногда замечаю, что на сайтах либо убирают событие onblur, чтобы по нажатию на кнопку submit, поле не потеряло значение и в поиск не ушла пустая строка, ну и другие не красивые решения, на скорую руку. Для себя я навалял &laquo;умную&raquo; функцию, которая всегда &laquo;знает&raquo; как себя правильно вести. Если кому нужно &#8211; забирайте.<br />
<span id="more-931"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> clearIt <span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> tmp_value<span style="color: #339933;">==</span><span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		tmp_value <span style="color: #339933;">=</span> obj.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">tagName</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'form'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> el<span style="color: #339933;">,</span> elName<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>obj.<span style="color: #660066;">elements</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			el <span style="color: #339933;">=</span> obj.<span style="color: #660066;">elements</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			elName <span style="color: #339933;">=</span> el.<span style="color: #660066;">nodeName</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>elName<span style="color: #339933;">==</span><span style="color: #3366CC;">'input'</span> <span style="color: #339933;">&amp;&amp;</span> el.<span style="color: #660066;">type</span><span style="color: #339933;">!=</span><span style="color: #3366CC;">'submit'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>tmp_value<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				el.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
				tmp_value <span style="color: #339933;">=</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">value</span><span style="color: #339933;">==</span>tmp_value<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		obj.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">value</span><span style="color: #339933;">===</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			obj.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> tmp_value<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Вызывать так:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;input type=&quot;password&quot; name=&quot;password&quot; value=&quot;password&quot; onfocus=&quot;clearIt(this);&quot; onblur=&quot;clearIt(this);&quot;&gt;</pre></div></div>

<p>Этот код эквивалентен:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;input name=&quot;story&quot; type=&quot;text&quot; onblur=&quot;if (this.value == '') {this.value = 'Искать...';}&quot;  onfocus=&quot;if (this.value == 'Искать...') {this.value = '';}&quot; value=&quot;Искать...&quot;&gt;</pre></div></div>

<p><strong>P.S.</strong><br />
Задумка, конечно не идеальна, но позволяет без дополнительных средств просто и эффективно реализовать достаточно наглядную форму, без не допиленного placeholder и монструозной jQuery.<br />
Если нужно, чтобы перед отправкой значение поля по умолчанию удалялось (если пользователь ничего не ввёл) &#8211; поместите в форму событие onsubmit=&raquo;clearIt(this);&raquo;.<br />
Функция пройдётся по всем input и очистит их значения. Кстати пример работы можно посмотреть <a href="http://www.bagrincev.ru/my/ex/cleatIt.html">здесь</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bagrincev.ru/javascript-text-inside-input-boxes-onblur-and-onfocus/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>PHP-&gt;HTML: проверить атрибуты HTML тегов (априори, парсинг HTML)</title>
		<link>http://www.bagrincev.ru/php-html-attributes-parsing/</link>
		<comments>http://www.bagrincev.ru/php-html-attributes-parsing/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 00:16:21 +0000</pubDate>
		<dc:creator>Sb0y</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[Программирование]]></category>
		<category><![CDATA[attributes]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[read]]></category>
		<category><![CDATA[атрибуты]]></category>
		<category><![CDATA[параметры]]></category>
		<category><![CDATA[парсинг]]></category>

		<guid isPermaLink="false">http://www.bagrincev.ru/?p=900</guid>
		<description><![CDATA[В данный момент я работаю над проектом, в котором любой пользователь извне может принять участие. В таких условиях приходиться внимательно следить за вводом HTML кода, поэтому я потратил достаточно много времени на написание функционала, отвечающего за фильтрацию пользовательского ввода. Если нежелательные теги и можно отсеять, используя встроенную функцию PHP strip_tags(), то для проверки атрибутов разрешённых ]]></description>
			<content:encoded><![CDATA[<p>В данный момент я работаю над проектом, в котором любой пользователь извне может принять участие. В таких условиях приходиться внимательно следить за вводом HTML кода, поэтому я потратил достаточно много времени на написание функционала, отвечающего за фильтрацию пользовательского ввода.<br />
<span id="more-900"></span><br />
Если нежелательные теги и можно отсеять, используя встроенную функцию PHP <a href="http://php.net/manual/en/function.strip-tags.php"><strong>strip_tags()</strong></a>, то для проверки атрибутов разрешённых HTML тегов придётся изобретать свой велосипед. Для <u>чтения</u> атрибутов, их параметров, названия тегов можно использовать эту функцию:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> read_htmlAttrs <span style="color: #009900;">&#40;</span><span style="color: #000088;">$source</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mb</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$m</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'strlen'</span><span style="color: #339933;">;</span> 
	<span style="color: #000088;">$m_s</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'substr'</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$mb</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$m</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'mb_'</span><span style="color: #339933;">.</span><span style="color: #000088;">$m</span><span style="color: #339933;">;</span> 
		<span style="color: #000088;">$m_s</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'mb_'</span><span style="color: #339933;">.</span><span style="color: #000088;">$m_s</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$srcLen</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$m</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$source</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$mode</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'full_idle'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">&lt;=</span><span style="color: #000088;">$srcLen</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$m_s</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$source</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$mode</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'full_idle'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$s</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'&lt;'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$m_s</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$source</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">'&lt;/'</span><span style="color: #009900;">&#41;</span> 
				<span style="color: #000088;">$mode</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'read_tag_name'</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$mode</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'read_tag_name'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/[a-zA-Z0-9&gt;\s]+/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'&gt;'</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$mode</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'close_tag'</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/[\s]+/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$mode</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'read_attr_name'</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
				<span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tagName'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$s</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$mode</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'read_attr_name'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/[a-zA-Z0-9&gt;=\s]+/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'&gt;'</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$mode</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'close_tag'</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'='</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
			       <span style="color: #000088;">$mode</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'read_param'</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
                        <span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attrName'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$s</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$mode</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'read_param'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'~[a-zA-Z0-9:&gt;;//#-_\s]+~i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/[\s]+/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$m_s</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$source</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">':'</span><span style="color: #009900;">&#41;</span> 
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">==</span><span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$mode</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'read_attr_name'</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attrName'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attrName'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'param'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'param'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'param'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'param'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attrName'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'param'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'&gt;'</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$mode</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'close_tag'</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'param'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$s</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$mode</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'close_tag'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$mode</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'full_idle'</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'param'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'param'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tagName'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tagName'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attrName'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attrName'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'param'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'param'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
       <span style="color: #009900;">&#125;</span>
   <span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Функция пройдётся по HTML-вводу и найдя теги (< и >) вернёт массив вида:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">Array</span>
<span style="color: #009900;">&#40;</span>
    <span style="color: #009900;">&#91;</span>attrName<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> ass
            <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> dev
        <span style="color: #009900;">&#41;</span>
&nbsp;
    <span style="color: #009900;">&#91;</span>param<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> dev
            <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> ass
        <span style="color: #009900;">&#41;</span>
&nbsp;
    <span style="color: #009900;">&#91;</span>tagName<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> span
        <span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>Это результат работы функции над:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>span ass<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dev&quot;</span> dev<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ass&quot;</span><span style="color: #339933;">&gt;</span>ololo<span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Этот массив можно использовать для замены нежелательных тегов, атрибутов и параметров (например style=&raquo;padding: 5000px;&raquo;) <img src='http://www.bagrincev.ru/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Второй, необязательный параметр, задаёт режим чтения. По умолчанию &#8211; мультибайтовый (подойдёт для UTF-8).</p>
<p>Простейший пример запуска после объявления функции:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$source</span> <span style="color: #339933;">=</span> read_htmlAtrrs <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Пример запуска, с отключением мультибайтовости:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$source</span> <span style="color: #339933;">=</span> read_htmlAtrrs <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bagrincev.ru/php-html-attributes-parsing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gentoo-&gt;bash: установка всех движков для GTK одной командой</title>
		<link>http://www.bagrincev.ru/gentoo-bash-gtk-engine/</link>
		<comments>http://www.bagrincev.ru/gentoo-bash-gtk-engine/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 08:31:50 +0000</pubDate>
		<dc:creator>Sb0y</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[Программирование]]></category>
		<category><![CDATA[Самопись]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[engine]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[движок]]></category>
		<category><![CDATA[установка]]></category>
		<category><![CDATA[шрифты]]></category>

		<guid isPermaLink="false">http://www.bagrincev.ru/?p=897</guid>
		<description><![CDATA[Если скаченная тема с gnome-look.org (или с xfce-look.org) некрасиво отображается, как &#171;голая&#187;, тоесть без декораций и картинок &#8211; скорее всего у вас в системе не установлен движок, который она использует для рендеринга. В Gentoo можно установить все темы одной командой: emerge `emerge -s '@gtk-engine' &#124; sed -rne 's:\W+x11-themes/(\S+)$:\1:p'` -avn --keep-going Кстати по той же системе ]]></description>
			<content:encoded><![CDATA[<p>Если скаченная тема с gnome-look.org (или с xfce-look.org) некрасиво отображается, как &laquo;голая&raquo;, тоесть без декораций и картинок &#8211; скорее всего у вас в системе не установлен движок, который она использует для рендеринга.</p>
<p>В Gentoo можно установить все темы одной командой:<br />
<span id="more-897"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">emerge <span style="color: #000000; font-weight: bold;">`</span>emerge <span style="color: #660033;">-s</span> <span style="color: #ff0000;">'@gtk-engine'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-rne</span> <span style="color: #ff0000;">'s:\W+x11-themes/(\S+)$:\1:p'</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #660033;">-avn</span> <span style="color: #660033;">--keep-going</span></pre></div></div>

<p>Кстати по той же системе из репозитория ставятся все возможные шрифты.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">emerge <span style="color: #000000; font-weight: bold;">`</span>emerge <span style="color: #660033;">-s</span> <span style="color: #ff0000;">'@font'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-rne</span> <span style="color: #ff0000;">'s:\W+media-fonts/(\S+)$:\1:p'</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #660033;">-avn</span> <span style="color: #660033;">--keep-going</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bagrincev.ru/gentoo-bash-gtk-engine/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP-&gt;Webasyst: программирование под популярный движок виртуального магазина</title>
		<link>http://www.bagrincev.ru/webasyst-programming/</link>
		<comments>http://www.bagrincev.ru/webasyst-programming/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 11:21:48 +0000</pubDate>
		<dc:creator>Sb0y</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[Программирование]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[smarty]]></category>
		<category><![CDATA[webasyst]]></category>

		<guid isPermaLink="false">http://www.bagrincev.ru/?p=786</guid>
		<description><![CDATA[Webasyst &#8211; движок, использующий Smarty в качестве шаблонизатора. Cвои функции всё равно можно писать, через интерфейс плагинов Smarty. Плюсы этого способа &#8211; простота освоения и лёгкая инсталляция. Минусы &#8211; из таких плагинов не работают множество полезных и удобных функций движка, которые при написании плагина сэкономили бы вам кучу времени, а так же, не оправданно сложная ]]></description>
			<content:encoded><![CDATA[<p><strong>Webasyst</strong> &#8211; движок, использующий Smarty в качестве шаблонизатора. Cвои функции всё равно можно писать, через интерфейс плагинов Smarty. Плюсы этого способа &#8211; простота освоения и лёгкая инсталляция. Минусы &#8211; из таких плагинов не работают множество полезных и удобных функций движка, которые при написании плагина сэкономили бы вам кучу времени, а так же, не оправданно сложная развёртка сложных структур.<br />
В этом мануале, я так же рассмотрю интерфейс самого движка, в котором работают все функции, используются классы и объекты, а установка сложнее.<br />
<span id="more-786"></span><br />
Я использовал при написании этого материала Webasyst версии <strong>285</strong>.</p>
<p>Для того, чтобы создать свой плагин, используя интерфейс Smarty, достаточно создать файл <strong>function.имяПлагина.php</strong> в директории <strong>/kernel/includes/smarty/plugins</strong> с таким содержанием:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> smarty_function_имяПлагина<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$params</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$smarty</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Hello World!'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>После этого в шаблон можно вставить тег {имяПлагина}, при выводе, он будет заменён на &laquo;Hello World!&raquo;.<br />
Если нужно передать функции параметр, можно использовать массив $params. </p>
<p>В коде шаблона:<br />
{имяПлагина var=&raquo;Hello World!&raquo;}</p>
<p>В коде плагина:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> smarty_function_имяПлагина<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$params</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$smarty</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'var'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Впринципе, не возбраняется использование классов и объектов</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> smarty_function_имяПлагина<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$params</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$smarty</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_form.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$frm</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> frm_reg <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$frm</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>require_once здесь используется не случайно. Бывают случаи, когда смарти из-за кеша пытается загрузить файл повторно, что приводит к ошибке.</p>
<p>Но главный недостаток остаётся всё равно &#8211; из этого интерфейса многие функции движка остаются недоступны. (например <strong>db_fetch_row()</strong>), поэтому переходим к интерфейсу движка.</p>
<p>Создадим папку нашего модуля. Делается это по адресу <strong>$app_root/html/scripts/modules</strong>, где <strong>$app_root</strong> &#8211; путь до установленного приложения на платформу Webasyst (например у shop-script полный путь будет выглядеть так <strong>/published/SC/</strong>html/scripts/modules/). Назовём её новыйМодуль.</p>
<p>Теперь необходимо создать XML файл с именем <strong>connector.новыйМодуль.xml</strong>, с содержанием:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Connector<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>новыйМодуль<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;File<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>class.новыйМодуль.php<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/File<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Любое название<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Любое описание<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SingleInstallation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SingleInstallation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Connector<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Как уже, наверняка стало понятно, в той же папке создаём класс модуля. <strong>class.новыйМодуль.php</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">class</span> Modulename <span style="color: #000000; font-weight: bold;">extends</span> ComponentModule  <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> initInterfaces<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__registerComponent<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modulename'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Любое название'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'general_layout'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'home_page'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'methodFShowModule'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> methodFShowModule<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$Register</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>Register<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$smarty</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$Register</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span>VAR_SMARTY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #666666; font-style: italic;">//передаём переменные в шаблон. может быть массивом</span>
		<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;vars&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Hello World!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #666666; font-style: italic;">//грузим файл шаблона</span>
		<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'новыйМодуль.tpl.html'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">exec</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//любые действия...</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Hello World!'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Опять же, создаём шаблон Smarty, в директории templates, с названием файла <strong>новыйМодуль.tpl.html</strong>.</p>
<p>Остаётся только зарегистрировать новый модуль в базе.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`SC_modules`</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #ff0000;">`ModuleVersion`</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`ModuleClassName`</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'новыйМодуль'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`ModuleClassFile`</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'/новыйМодуль/class.новыйМодуль.php'</span></pre></div></div>

<p>Поскольку идентификатор добавленной позиции добавляется autoincrement&#8217;ом, нужно его узнать.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">`ModuleID`</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">`SC_modules`</span> <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #ff0000;">`ModuleClassName`</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'новыйМодуль'</span>;</pre></div></div>

<p>Полученное число подставляем в следующий запрос.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`SC_module_configs`</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #ff0000;">`ModuleID`</span><span style="color: #66cc66;">=</span>полученное_ранее_число<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`ConfigKey`</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'новыйМодуль'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`ConfigInit`</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1002</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`ConfigEnabled`</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span>;</pre></div></div>

<p>Опять узаём ID. На это раз, для удобства и понимания назовём полученное число &laquo;ID&raquo; и подставим его в следующий запрос.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">`ModuleConfigID`</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">`SC_module_configs`</span> <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #ff0000;">`ModuleID`</span><span style="color: #66cc66;">=</span>полученное_ранее_число;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`SC_interface_interfaces`</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #ff0000;">`xInterfaceCaller`</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'51_cpt_connector'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`xInterfaceCalled`</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'ID_новыйМодуль'</span>;</pre></div></div>

<p>Если всё сделано правильно, в шаблон можно будет вставить тег <strong>{cpt_новыйМодуль}</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bagrincev.ru/webasyst-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Построение древовидных данных в PHP</title>
		<link>http://www.bagrincev.ru/php-tree-data/</link>
		<comments>http://www.bagrincev.ru/php-tree-data/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 05:27:34 +0000</pubDate>
		<dc:creator>Sb0y</dc:creator>
				<category><![CDATA[Программирование]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tree]]></category>
		<category><![CDATA[древо]]></category>

		<guid isPermaLink="false">http://www.bagrincev.ru/?p=771</guid>
		<description><![CDATA[Недавно, возникла потребность сделать древовидный, порядковый список категорий, в одном из проектов. 2 главных условий, которые преследовал: 1) в html должны наглядно показываться родительские элементы и их &#171;дети&#187;; 2) для всей операции 1 SQL запрос. SQL-структура была такая: +------------+--------------+------+-----+---------+----------------+ &#124; FIELD &#124; Type &#124; NULL &#124; KEY &#124; DEFAULT &#124; Extra +------------+--------------+------+-----+---------+----------------+ &#124; categoryID &#124; ]]></description>
			<content:encoded><![CDATA[<p>Недавно, возникла потребность сделать древовидный, порядковый список категорий, в одном из проектов.</p>
<p>2 главных условий, которые преследовал: 1) в html должны наглядно показываться родительские элементы и их &laquo;дети&raquo;; 2) для всей операции 1 SQL запрос.<br />
<span id="more-771"></span><br />
SQL-структура была такая:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+--------------+------+-----+---------+----------------+</span>
<span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">FIELD</span>          <span style="color: #66cc66;">|</span> Type             <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>   <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span>   <span style="color: #66cc66;">|</span> Extra 
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+--------------+------+-----+---------+----------------+</span>
<span style="color: #66cc66;">|</span> categoryID <span style="color: #66cc66;">|</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>            <span style="color: #66cc66;">|</span> NO    <span style="color: #66cc66;">|</span> PRI   <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span>  <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> parent       <span style="color: #66cc66;">|</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>            <span style="color: #66cc66;">|</span> NO    <span style="color: #66cc66;">|</span>        <span style="color: #66cc66;">|</span> <span style="color: #cc66cc;">0</span>          <span style="color: #66cc66;">|</span>                        <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> name        <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>   <span style="color: #66cc66;">|</span> NO    <span style="color: #66cc66;">|</span>        <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>     <span style="color: #66cc66;">|</span>                        <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> slug          <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>   <span style="color: #66cc66;">|</span> NO    <span style="color: #66cc66;">|</span>        <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>     <span style="color: #66cc66;">|</span>                        <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> pic           <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>   <span style="color: #66cc66;">|</span> YES   <span style="color: #66cc66;">|</span>        <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>     <span style="color: #66cc66;">|</span>                        <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+--------------+------+-----+---------+----------------+</span>
<span style="color: #cc66cc;">5</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.03</span> sec<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>После запроса в БД массив получился такой.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">Array</span>
<span style="color: #009900;">&#40;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>categoryID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span>
            <span style="color: #009900;">&#91;</span>parent<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span>
            <span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Фильмы
            <span style="color: #009900;">&#91;</span>slug<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> films
            <span style="color: #009900;">&#91;</span>pic<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> 
        <span style="color: #009900;">&#41;</span>
&nbsp;
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>categoryID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span>
            <span style="color: #009900;">&#91;</span>parent<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span>
            <span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Музыка
            <span style="color: #009900;">&#91;</span>slug<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> music
            <span style="color: #009900;">&#91;</span>pic<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> 
        <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#91;</span><span style="color: #339933;">...</span><span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>Для удобной работы я сгруппировал массив по <strong>categoryID</strong>, заменив его ключи на этот идентификатор.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span>
<span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'categoryID'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$v</span><span style="color: #339933;">;</span></pre></div></div>

<p>А вот и сама функция, которая пишет в глобальный массив $g_data результат своей рекурсивной работы.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> tree<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$node_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lvl</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$lvl</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// для каждой категории может быть действие (напр. присвоить id)</span>
	<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">:</span>
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;option style=&quot;font-weight:bolder;&quot; disabled&gt;- КОРЕНЬ -&lt;/strong&gt;'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
        <span style="color: #666666; font-style: italic;">// str_repeat делает отступ слева, в зависимости от уровня кат-ии. Это наглядно показывает юзеру родителя категории и его дочерний элемент. А если кат-я самая &quot;верхняя&quot;, она выделяется стилем font-weight:bold</span>
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;option '</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$node_id</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'parent'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span>?<span style="color: #0000ff;">'style=&quot;font-weight:bold;'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' value=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$node_id</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'categoryID'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #990000;">str_repeat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;nbsp;&amp;nbsp;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lvl</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$node_id</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/option&gt;'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">g_data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tree'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// рекурсия</span>
   <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'parent'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$node_id</span><span style="color: #009900;">&#41;</span>
         <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tree</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'categoryID'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lvl</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Остаётся только запустить процесс.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">tree<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bagrincev.ru/php-tree-data/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>1С: PHPXML</title>
		<link>http://www.bagrincev.ru/1c-php-xml/</link>
		<comments>http://www.bagrincev.ru/1c-php-xml/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 12:22:12 +0000</pubDate>
		<dc:creator>Sb0y</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[Программирование]]></category>
		<category><![CDATA[1C]]></category>
		<category><![CDATA[1С]]></category>
		<category><![CDATA[autofs]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[simplexml]]></category>
		<category><![CDATA[smb]]></category>
		<category><![CDATA[smbfs]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.bagrincev.ru/?p=757</guid>
		<description><![CDATA[Предположим, есть задание выгружать данные из 1С и использовать их в своих WEB-проектах (интернет-магазин с реальным ассортиментом и балансом). Очень удобно, в этом случае получить от 1С данные в XML, файле, а потом распарсить их и разнести по SQL таблицам. У нас получилась вот такая вот выгрузка: &#60;Vitrina Элементов=&#34;10&#34;&#62; &#60;Элемент ID=&#34;8362217666&#34; ParentID=&#34;83014&#34; Товар=&#34;100 человек, которые ]]></description>
			<content:encoded><![CDATA[<p>Предположим, есть задание выгружать данные из 1С и использовать их в своих WEB-проектах (интернет-магазин с реальным ассортиментом и балансом).</p>
<p>Очень удобно, в этом случае получить от 1С данные в XML, файле, а потом распарсить их и разнести по SQL таблицам.</p>
<p>У нас получилась вот такая вот выгрузка:<br />
<span id="more-757"></span></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Vitrina</span> Элементов=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;Элемент <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;8362217666&quot;</span> <span style="color: #000066;">ParentID</span>=<span style="color: #ff0000;">&quot;83014&quot;</span> Товар=<span style="color: #ff0000;">&quot;100 человек, которые изменили ход истории&quot;</span> Номер=<span style="color: #ff0000;">&quot;95/2009&quot;</span> Фото=<span style="color: #ff0000;">&quot;&quot;</span> Витрина=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;Элемент <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;8362211581&quot;</span> <span style="color: #000066;">ParentID</span>=<span style="color: #ff0000;">&quot;6636&quot;</span> Товар=<span style="color: #ff0000;">&quot;Mens Health mini&quot;</span> Номер=<span style="color: #ff0000;">&quot;12/2009&quot;</span> Фото=<span style="color: #ff0000;">&quot;Y:\Company\Общие файлы 1с\Фото\8362211581.jpg&quot;</span> Витрина=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;Элемент <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;8362201090&quot;</span> <span style="color: #000066;">ParentID</span>=<span style="color: #ff0000;">&quot;938&quot;</span> Товар=<span style="color: #ff0000;">&quot;Newsweek&quot;</span> Номер=<span style="color: #ff0000;">&quot;47/2009&quot;</span> Фото=<span style="color: #ff0000;">&quot;&quot;</span> Витрина=<span style="color: #ff0000;">&quot;3&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;Элемент <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;92000054&quot;</span> <span style="color: #000066;">ParentID</span>=<span style="color: #ff0000;">&quot;920&quot;</span> Товар=<span style="color: #ff0000;">&quot;Rolling Stone&quot;</span> Номер=<span style="color: #ff0000;">&quot;11/2009&quot;</span> Фото=<span style="color: #ff0000;">&quot;Y:\Company\Общие файлы 1с\Фото\92000054.jpg&quot;</span> Витрина=<span style="color: #ff0000;">&quot;4&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;Элемент <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;8285200104&quot;</span> <span style="color: #000066;">ParentID</span>=<span style="color: #ff0000;">&quot;82852&quot;</span> Товар=<span style="color: #ff0000;">&quot;StarHit&quot;</span> Номер=<span style="color: #ff0000;">&quot;46/2009&quot;</span> Фото=<span style="color: #ff0000;">&quot;Y:\Company\Общие файлы 1с\Фото\8285200104.bmp&quot;</span> Витрина=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;Элемент <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;648900054&quot;</span> <span style="color: #000066;">ParentID</span>=<span style="color: #ff0000;">&quot;6489&quot;</span> Товар=<span style="color: #ff0000;">&quot;Total DVD&quot;</span> Номер=<span style="color: #ff0000;">&quot;11/2009&quot;</span> Фото=<span style="color: #ff0000;">&quot;Y:\Company\Общие файлы 1с\Фото\648900054.bmp&quot;</span> Витрина=<span style="color: #ff0000;">&quot;6&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;Элемент <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;687800218&quot;</span> <span style="color: #000066;">ParentID</span>=<span style="color: #ff0000;">&quot;6878&quot;</span> Товар=<span style="color: #ff0000;">&quot;Антенна-Телесемь&quot;</span> Номер=<span style="color: #ff0000;">&quot;48/2009&quot;</span> Фото=<span style="color: #ff0000;">&quot;&quot;</span> Витрина=<span style="color: #ff0000;">&quot;7&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;Элемент <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;8362219837&quot;</span> <span style="color: #000066;">ParentID</span>=<span style="color: #ff0000;">&quot;83587&quot;</span> Товар=<span style="color: #ff0000;">&quot;Веселый художник&quot;</span> Номер=<span style="color: #ff0000;">&quot;23/2009 - 2360&quot;</span> Фото=<span style="color: #ff0000;">&quot;&quot;</span> Витрина=<span style="color: #ff0000;">&quot;8&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;Элемент <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;8362203118&quot;</span> <span style="color: #000066;">ParentID</span>=<span style="color: #ff0000;">&quot;82838&quot;</span> Товар=<span style="color: #ff0000;">&quot;Empire&quot;</span> Номер=<span style="color: #ff0000;">&quot;11/2009&quot;</span> Фото=<span style="color: #ff0000;">&quot;Y:\Company\Общие файлы 1с\Фото\8362203118.jpg&quot;</span> Витрина=<span style="color: #ff0000;">&quot;9&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;">&lt;Элемент <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;682300047&quot;</span> <span style="color: #000066;">ParentID</span>=<span style="color: #ff0000;">&quot;6823&quot;</span> Товар=<span style="color: #ff0000;">&quot;In Style&quot;</span> Номер=<span style="color: #ff0000;">&quot;12/2009&quot;</span> Фото=<span style="color: #ff0000;">&quot;Y:\Company\Общие файлы 1с\Фото\682300047.jpg&quot;</span> Витрина=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Vitrina<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Если вы думаете, что работа с  XML в PHP нудна и не целесообразна, спешу разочаровать <img src='http://www.bagrincev.ru/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Весь парсинг сводится к элементарной конструкции:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#загрузим XML файл
</span><span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'XML/Выгрузка/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$files</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#данные получаются в виде объектов, представляющие собой массивы
</span><span style="color: #000088;">$val</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span>Элемент<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Номер'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#на экран!
</span><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$val</span><span style="color: #339933;">;</span></pre></div></div>

<p>Просто, не правда ли? <img src='http://www.bagrincev.ru/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Кстати, <strong>print_r($xml)</strong> выглядит примерно так:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">SimpleXMLElement Object <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">@</span>attributes<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span>Элементов<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#91;</span>Элемент<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> SimpleXMLElement Object <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">@</span>attributes<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span>ID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8362217666</span> <span style="color: #009900;">&#91;</span>ParentID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">83014</span> <span style="color: #009900;">&#91;</span>Товар<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">100</span> человек<span style="color: #339933;">,</span> которые изменили ход истории <span style="color: #009900;">&#91;</span>Номер<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">95</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2009</span> <span style="color: #009900;">&#91;</span>Фото<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span>Витрина<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> SimpleXMLElement Object <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">@</span>attributes<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span>ID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8362211581</span> <span style="color: #009900;">&#91;</span>ParentID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">6636</span> <span style="color: #009900;">&#91;</span>Товар<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Mens Health mini <span style="color: #009900;">&#91;</span>Номер<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2009</span> <span style="color: #009900;">&#91;</span>Фото<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Y<span style="color: #339933;">:</span>\Company\Общие файлы <span style="color: #cc66cc;">1</span>с\Фото\8362211581<span style="color: #339933;">.</span>jpg <span style="color: #009900;">&#91;</span>Витрина<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> SimpleXMLElement Object <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">@</span>attributes<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span>ID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8362201090</span> <span style="color: #009900;">&#91;</span>ParentID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">938</span> <span style="color: #009900;">&#91;</span>Товар<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Newsweek <span style="color: #009900;">&#91;</span>Номер<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">47</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2009</span> <span style="color: #009900;">&#91;</span>Фото<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span>Витрина<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> SimpleXMLElement Object <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">@</span>attributes<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span>ID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">92000054</span> <span style="color: #009900;">&#91;</span>ParentID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">920</span> <span style="color: #009900;">&#91;</span>Товар<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Rolling Stone <span style="color: #009900;">&#91;</span>Номер<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">11</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2009</span> <span style="color: #009900;">&#91;</span>Фото<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Y<span style="color: #339933;">:</span>\Company\Общие файлы <span style="color: #cc66cc;">1</span>с\Фото\92000054<span style="color: #339933;">.</span>jpg <span style="color: #009900;">&#91;</span>Витрина<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> SimpleXMLElement Object <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">@</span>attributes<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span>ID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8285200104</span> <span style="color: #009900;">&#91;</span>ParentID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">82852</span> <span style="color: #009900;">&#91;</span>Товар<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> StarHit <span style="color: #009900;">&#91;</span>Номер<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">46</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2009</span> <span style="color: #009900;">&#91;</span>Фото<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Y<span style="color: #339933;">:</span>\Company\Общие файлы <span style="color: #cc66cc;">1</span>с\Фото\8285200104<span style="color: #339933;">.</span>bmp <span style="color: #009900;">&#91;</span>Витрина<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> SimpleXMLElement Object <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">@</span>attributes<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span>ID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">648900054</span> <span style="color: #009900;">&#91;</span>ParentID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">6489</span> <span style="color: #009900;">&#91;</span>Товар<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Total DVD <span style="color: #009900;">&#91;</span>Номер<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">11</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2009</span> <span style="color: #009900;">&#91;</span>Фото<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Y<span style="color: #339933;">:</span>\Company\Общие файлы <span style="color: #cc66cc;">1</span>с\Фото\648900054<span style="color: #339933;">.</span>bmp <span style="color: #009900;">&#91;</span>Витрина<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">6</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> SimpleXMLElement Object <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">@</span>attributes<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span>ID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">687800218</span> <span style="color: #009900;">&#91;</span>ParentID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">6878</span> <span style="color: #009900;">&#91;</span>Товар<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Антенна<span style="color: #339933;">-</span>Телесемь <span style="color: #009900;">&#91;</span>Номер<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">48</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2009</span> <span style="color: #009900;">&#91;</span>Фото<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span>Витрина<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">7</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> SimpleXMLElement Object <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">@</span>attributes<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span>ID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8362219837</span> <span style="color: #009900;">&#91;</span>ParentID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">83587</span> <span style="color: #009900;">&#91;</span>Товар<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Веселый художник <span style="color: #009900;">&#91;</span>Номер<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">23</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2009</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">2360</span> <span style="color: #009900;">&#91;</span>Фото<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span>Витрина<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> SimpleXMLElement Object <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">@</span>attributes<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span>ID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8362203118</span> <span style="color: #009900;">&#91;</span>ParentID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">82838</span> <span style="color: #009900;">&#91;</span>Товар<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Empire <span style="color: #009900;">&#91;</span>Номер<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">11</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2009</span> <span style="color: #009900;">&#91;</span>Фото<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Y<span style="color: #339933;">:</span>\Company\Общие файлы <span style="color: #cc66cc;">1</span>с\Фото\8362203118<span style="color: #339933;">.</span>jpg <span style="color: #009900;">&#91;</span>Витрина<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">9</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> SimpleXMLElement Object <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">@</span>attributes<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span>ID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">682300047</span> <span style="color: #009900;">&#91;</span>ParentID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">6823</span> <span style="color: #009900;">&#91;</span>Товар<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> In Style <span style="color: #009900;">&#91;</span>Номер<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2009</span> <span style="color: #009900;">&#91;</span>Фото<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Y<span style="color: #339933;">:</span>\Company\Общие файлы <span style="color: #cc66cc;">1</span>с\Фото\682300047<span style="color: #339933;">.</span>jpg <span style="color: #009900;">&#91;</span>Витрина<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span></pre></div></div>

<p>Что на само по себе, на деле довольно удобно.</p>
<p>Чтобы примонтировать сетевую шару с 1С-выгрузками, лучше всего использовать <strong>autofs</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">site sb0y # emerge -av autofs
&nbsp;
These are the packages that would be merged, in order:
&nbsp;
Calculating dependencies... done!
[ebuild   R   ] net-fs/autofs-5.0.3-r6  USE=&quot;-ldap -sasl&quot; 0 kB
&nbsp;
Total: 1 package (1 reinstall), Size of downloads: 0 kB
&nbsp;
Would you like to merge these packages? [Yes/No]</pre></div></div>

<p>Она корректно примонтирует шару, отключится, если она (шара) вдруг исчезнет из сети или долго не будет использоваться, подключиться назад, если шара появится или понадобится какому-то процессу (например нашему парсеру).</p>
<p>Создадим новую область работы autofs:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'/mnt/net /etc/auto.auto  --ghost'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>auto.master</pre></div></div>

<p>Настроим эту область</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>auto.auto 
&nbsp;
smb <span style="color: #660033;">-fstype</span>=smbfs,<span style="color: #007800;">credentials</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>smb.auth,<span style="color: #007800;">iocharset</span>=utf8	 :<span style="color: #000000; font-weight: bold;">//</span>server<span style="color: #000000; font-weight: bold;">/</span>share</pre></div></div>

<p>Где <strong>credentials</strong> указывает на файл, в котором содержатся данные для авторизации:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>smb.auth
&nbsp;
<span style="color: #007800;">username</span>=<span style="color: #c20cb9; font-weight: bold;">login</span>
<span style="color: #007800;">password</span>=secretPassword</pre></div></div>

<p>Ну и в завершение &#8211; симлинк, в WWW-ROOT сервера, указывающий на папку с выгрузкой.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>magazine<span style="color: #000000; font-weight: bold;">/</span>htdocs<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>smb<span style="color: #000000; font-weight: bold;">/</span>Общие\ файлы\ <span style="color: #000000;">1</span>с<span style="color: #000000; font-weight: bold;">/</span>Интернет_магазин<span style="color: #000000; font-weight: bold;">/</span> XML</pre></div></div>

<p>Теперь XML-файлы доступны по адресу <strong>http://ваш-сайт/XML/file.xml</strong>. Лучше конечно ограничить к ним доступ, используя <strong>.htaccess</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bagrincev.ru/1c-php-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Музыкальный будильник</title>
		<link>http://www.bagrincev.ru/%d0%bc%d1%83%d0%b7%d1%8b%d0%ba%d0%b0%d0%bb%d1%8c%d0%bd%d1%8b%d0%b9-%d0%b1%d1%83%d0%b4%d0%b8%d0%bb%d1%8c%d0%bd%d0%b8%d0%ba/</link>
		<comments>http://www.bagrincev.ru/%d0%bc%d1%83%d0%b7%d1%8b%d0%ba%d0%b0%d0%bb%d1%8c%d0%bd%d1%8b%d0%b9-%d0%b1%d1%83%d0%b4%d0%b8%d0%bb%d1%8c%d0%bd%d0%b8%d0%ba/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 13:41:57 +0000</pubDate>
		<dc:creator>Sb0y</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[Программирование]]></category>
		<category><![CDATA[Самопись]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[mpd]]></category>
		<category><![CDATA[sh]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[будильник]]></category>

		<guid isPermaLink="false">http://www.bagrincev.ru/?p=753</guid>
		<description><![CDATA[Решил сделать так, чтобы каждое утро меня будила моя Ubuntu Linux. В биусе была включена функция Alarm, и был написан такой скриптик: #!/bin/sh &#160; #получаем время, конкретнее часы без минут и секунд time=`date \+\%H` &#160; #выставляем громкость и включаем каналы на звуковых картах amixer sset Master 90% amixer -c 1 sset PCM 100% unmute amixer ]]></description>
			<content:encoded><![CDATA[<p>Решил сделать так, чтобы каждое утро меня будила моя Ubuntu Linux.</p>
<p>В биусе была включена функция Alarm, и был написан такой скриптик:<br />
<span id="more-753"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#получаем время, конкретнее часы без минут и секунд</span>
<span style="color: #007800;"><span style="color: #000000; font-weight: bold;">time</span></span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> \+\<span style="color: #000000; font-weight: bold;">%</span>H<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#выставляем громкость и включаем каналы на звуковых картах</span>
amixer sset Master <span style="color: #000000;">90</span><span style="color: #000000; font-weight: bold;">%</span>
amixer <span style="color: #660033;">-c</span> <span style="color: #000000;">1</span> sset PCM <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> unmute
amixer <span style="color: #660033;">-c</span> <span style="color: #000000;">1</span> sset Mic <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Если полученное время ровняется числу 8, говорим mpd начать играть.</span>
<span style="color: #666666; font-style: italic;"># Делается, чтобы музыка начинала играть в 8 часов, а не каждый запуск.</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$time</span>&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #ff0000;">&quot;8&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span> mpc play ; <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span></pre></div></div>

<p>Скрипт можно вызвать из <strong>/etc/rc.local</strong>, но он выполняется от имени root&#8217;а, поэтому, делать это лучше вот так:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">su</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'/usr/bin/wakeup'</span> sb0y</pre></div></div>

<p>где <strong>sb0y</strong> &#8211; имя пользователя, от имени, которого будет запускаться скрипт.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bagrincev.ru/%d0%bc%d1%83%d0%b7%d1%8b%d0%ba%d0%b0%d0%bb%d1%8c%d0%bd%d1%8b%d0%b9-%d0%b1%d1%83%d0%b4%d0%b8%d0%bb%d1%8c%d0%bd%d0%b8%d0%ba/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Сделать категории VirtueMart в столбик</title>
		<link>http://www.bagrincev.ru/%d1%81%d0%b4%d0%b5%d0%bb%d0%b0%d1%82%d1%8c-%d0%ba%d0%b0%d1%82%d0%b5%d0%b3%d0%be%d1%80%d0%b8%d0%b8-virtuemart-%d0%b2-%d1%81%d1%82%d0%be%d0%b1%d0%b8%d0%ba/</link>
		<comments>http://www.bagrincev.ru/%d1%81%d0%b4%d0%b5%d0%bb%d0%b0%d1%82%d1%8c-%d0%ba%d0%b0%d1%82%d0%b5%d0%b3%d0%be%d1%80%d0%b8%d0%b8-virtuemart-%d0%b2-%d1%81%d1%82%d0%be%d0%b1%d0%b8%d0%ba/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 16:25:59 +0000</pubDate>
		<dc:creator>Sb0y</dc:creator>
				<category><![CDATA[Программирование]]></category>

		<guid isPermaLink="false">http://www.bagrincev.ru/?p=550</guid>
		<description><![CDATA[Была задача, сделать отображение в столбик категорий VirtueMart (который в свою очаредь был взять с virtuemart.ru), кототрый столя на Joomla 1.0.x. Древний такой магаз достался, почти как говно мамонта, но решать задачу всё равно было нужно и вот что я сделал. Есть файл такой /administrator/components/com_virtuemart/html/shop.index.php. Этот файл что-то типо центрального шаблонизатора он выдаёт динамический HTML-код, ]]></description>
			<content:encoded><![CDATA[<p>Была задача, сделать отображение в столбик категорий VirtueMart (который в свою очаредь был взять с <a href="http://virtuemart.ru/" target="_blank">virtuemart.ru</a>), кототрый столя на Joomla 1.0.x.</p>
<p>Древний такой магаз достался, почти как говно мамонта, но решать задачу всё равно было нужно и вот что я сделал.</p>
<p>Есть файл такой <strong>/administrator/components/com_virtuemart/html/shop.index.php</strong>.</p>
<p>Этот файл что-то типо центрального шаблонизатора он выдаёт динамический HTML-код, нам нужны таблицы отвечающие за показ ссылок на категории.</p>
<p>Итак, находим код:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'_VALID_MOS'</span> <span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Direct Access to this location is not allowed.'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/**
*
* @version $Id: shop.index.php 638 2007-01-16 18:48:21Z soeren_nb $
* @package VirtueMart
* @subpackage html
* @copyright Copyright (C) 2004-2005 Soeren Eberhardt. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* http://virtuemart.net
*/</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span> CLASSPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'ps_product.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span> CLASSPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'ps_product_category.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ps_product</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ps_product<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Show only top level categories and categories that are</span>
<span style="color: #666666; font-style: italic;">// being published</span>
<span style="color: #000088;">$query</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM #__{vm}_category, #__{vm}_category_xref &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;WHERE #__{vm}_category.category_publish='Y' AND &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;(#__{vm}_category_xref.category_parent_id='' OR #__{vm}_category_xref.category_parent_id='0') AND &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;#__{vm}_category.category_id=#__{vm}_category_xref.category_child_id &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;ORDER BY #__{vm}_category.list_order, #__{vm}_category.category_name ASC&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// initialise the query in the $database connector</span>
<span style="color: #666666; font-style: italic;">// this translates the '#__' prefix into the real database prefix</span>
<span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$query</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$iCol</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$categories_per_row</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$cellwidth</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">100</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$categories_per_row</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Нам нужна строчка 35, в ней поставить значение переменной <strong>$categories_per_row</strong> &#8211; <strong>1</strong> за место <strong>4</strong></p>
<p>Далее, мне понадобилось, чтобы между категориями был отступ. Это задачу я решил так:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;p&gt;&lt;a title=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$catname</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; href=&quot;&lt; ?php echo $sess-&gt;url(URL.&quot;index.php?option=com_virtuemart&amp;amp;page=shop.browse&amp;amp;category_id=&quot;.$db-&gt;f(&quot;category_id&quot;)); ?&gt;&quot;&gt;&lt;/a&gt;&lt;/p&gt;</pre></div></div>

<p>Тоесть в 55-й строчке (считать строчки в файле <strong>shop.index.php</strong>) нужно добавить HTML тег &laquo;&lt;p&gt;&raquo; и закрыть его, соотвественно.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bagrincev.ru/%d1%81%d0%b4%d0%b5%d0%bb%d0%b0%d1%82%d1%8c-%d0%ba%d0%b0%d1%82%d0%b5%d0%b3%d0%be%d1%80%d0%b8%d0%b8-virtuemart-%d0%b2-%d1%81%d1%82%d0%be%d0%b1%d0%b8%d0%ba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Автоматическое формирование Magnet-ссылок</title>
		<link>http://www.bagrincev.ru/%d0%b0%d0%b2%d1%82%d0%be%d0%bc%d0%b0%d1%82%d0%b8%d1%87%d0%b5%d1%81%d0%ba%d0%be%d0%b5-%d1%84%d0%be%d1%80%d0%bc%d0%b8%d1%80%d0%be%d0%b2%d0%b0%d0%bd%d0%b8%d0%b5-magnet-%d1%81%d1%81%d1%8b%d0%bb%d0%be/</link>
		<comments>http://www.bagrincev.ru/%d0%b0%d0%b2%d1%82%d0%be%d0%bc%d0%b0%d1%82%d0%b8%d1%87%d0%b5%d1%81%d0%ba%d0%be%d0%b5-%d1%84%d0%be%d1%80%d0%bc%d0%b8%d1%80%d0%be%d0%b2%d0%b0%d0%bd%d0%b8%d0%b5-magnet-%d1%81%d1%81%d1%8b%d0%bb%d0%be/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 11:34:26 +0000</pubDate>
		<dc:creator>Sb0y</dc:creator>
				<category><![CDATA[О DC портале]]></category>
		<category><![CDATA[Программирование]]></category>

		<guid isPermaLink="false">http://www.bagrincev.ru/?p=234</guid>
		<description><![CDATA[Недавно обкатал новую интересную функцию на DC портале. Для неё использовал в классе парсера функцию PHP &#171;preg_replace_callback&#171;. Суть функции заключается в том что она берёт параметром функцию обратного вызова ко всем найденным выражениям и найденное заменяет тем что функция вернула. Внутри функции заключил 2 функции: первая, format_size, формирует размер, кстати вот она: function format_size &#40;$size, ]]></description>
			<content:encoded><![CDATA[<p>Недавно обкатал новую интересную функцию на DC портале. Для неё использовал в классе парсера функцию PHP &laquo;<strong>preg_replace_callback</strong>&laquo;. Суть функции заключается в том что она берёт параметром функцию обратного вызова ко всем найденным выражениям и найденное заменяет тем что функция вернула.</p>
<p>Внутри функции заключил 2 функции: первая, <strong>format_size</strong>, формирует размер, кстати вот она:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> format_size <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #339933;">,</span> <span style="color: #000088;">$arr</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #000088;">$units</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #000088;">$units</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1048576</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;"># 1024^2
</span>	<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$units</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Kb&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$size</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">1024</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1073741824</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;"># 1024^3
</span>  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$units</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Mb&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$size</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1048576</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1099511627776</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;"># 1024^4
</span>		<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$units</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;GB&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$size</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1073741824</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1125899906842624</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;"># 1024^5
</span>		    <span style="color: #009900;">&#123;</span>
		    <span style="color: #000088;">$units</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Tb&quot;</span><span style="color: #339933;">;</span>
		    <span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$size</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1099511627776</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		    <span style="color: #000088;">$units</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Eb&quot;</span><span style="color: #339933;">;</span>
		    <span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$size</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1125899906842624</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;"># 1024^5
</span>				<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$units</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">.</span><span style="color: #000088;">$units</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Вторая, <strong>rep_magnet</strong>, берёт этот размер и формирует, собственно Magnet-ссылку.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> rep_magnet <span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$s</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// If have '[url=' at the start - return not modiffed string</span>
<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$s</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">urldecode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> format_size<span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&lt;img src=&quot;/favicon.png/&quot; alt=&quot;&quot; /&gt;&lt;a href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$link</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;Скачать файл из DC++: &lt;strong&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/strong&gt;&lt;/a&gt; ('</span><span style="color: #339933;">.</span><span style="color: #000088;">$size</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Если функция находит символ равно, в регулярном выражении, обработки не происходит, сделанно, для экранирования ссылок заключённых в тег [url и воизбежании повторного парсинга.</p>
<p>В итоге получается такая регулярка:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$source</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace_callback</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/([=\'&quot;`])?magnet:\?xt=urn:tree:tiger:([a-z0-9]+)&amp;amp;xl=([0-9]+)&amp;amp;dn=([^&amp;lt;\s\[\]]+)/uims'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rep_magnet'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$source</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Вот так это выглядит в работе:</p>
<p><img class="alignnone size-full wp-image-251" title="d0b1d0b5d0b7-d0b8d0bcd0b5d0bdd0b81" src="http://www.bagrincev.ru/uploads/d0b1d0b5d0b7-d0b8d0bcd0b5d0bdd0b81.png" alt="d0b1d0b5d0b7-d0b8d0bcd0b5d0bdd0b81" width="369" height="61" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bagrincev.ru/%d0%b0%d0%b2%d1%82%d0%be%d0%bc%d0%b0%d1%82%d0%b8%d1%87%d0%b5%d1%81%d0%ba%d0%be%d0%b5-%d1%84%d0%be%d1%80%d0%bc%d0%b8%d1%80%d0%be%d0%b2%d0%b0%d0%bd%d0%b8%d0%b5-magnet-%d1%81%d1%81%d1%8b%d0%bb%d0%be/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
