<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>lescinskas.lt</title>
    <description><![CDATA[Žymės įrašai :: rss]]></description>
    <link>http://www.lescinskas.lt/lt/blog</link>
    <language>lt</language>
    <item>
      <title>Iliustracijų korekcija RSS agregatoriuose</title>
      <description><![CDATA[<p><img height="100" width="100" src="/uploads/editor/image/flying-monkeys.gif" alt="Flying monkeys stole my icon" /></p>
<p>Neretai pasitaiko, jog tinklaraščių įrašuose kelias iki iliustracijų yra pateikiamas reliatyviai (pvz.: &lt;img src=&quot;/images/foo.bar&quot; /&gt;). Analogiškas HTML kodas bus pateikiamas ir to tinklaraščio RSS šaltinyje, todėl RSS skaitymo programose arba agregatoriuose tokia iliustracija daugeliu atveju nebus atvaizduota (nes bus ieškoma ne tinklaraščio, o agregatoriaus serveryje).</p>
<p>Šiai situacijai yra du sprendimo būdai: iliutracijų korekcija RSS šaltinyje arba RSS skaitymo programoje ar agregatoriuje (daugelis jų atlieka šį veiksmą).</p>
<p>Pateikiu PHP kodą, kuris tinka abiejais atvejais. Jis HTML kode esantiems paveikslėliams preprend'ina HTTP host'ą:</p>
<p><code><span style="color: rgb(0, 0, 0);"> <span style="color: rgb(0, 0, 187);">&lt;?php <br />
</span><span style="color: rgb(255, 128, 0);">//&nbsp;Tekstas,&nbsp;kurį&nbsp;reikia&nbsp;išparsinti: <br />
</span><span style="color: rgb(0, 0, 187);">$blogEntry&nbsp;</span><span style="color: rgb(0, 119, 0);">=&nbsp;</span><span style="color: rgb(221, 0, 0);">'Kažkoks&nbsp;blogo&nbsp;įrašo&nbsp;tekstas&lt;b&gt;  <br />
&lt;img&nbsp;src=&quot;http://www.cards.lt/img/cards_logo_small.jpg&quot; <br />
alt=&quot;Logo&quot;&nbsp;/&gt;&lt;/b&gt; <br />
&lt;img&nbsp;alt=&quot;Logo&quot; <br />
src=&quot;/img/cards-125x125.jpg&quot;&nbsp;width=&quot;125&quot;&nbsp;height=&quot;125&quot;&nbsp;/&gt;'</span><span style="color: rgb(0, 119, 0);">; <br />
<br />
</span><span style="color: rgb(255, 128, 0);">//&nbsp;RSS'o&nbsp;URL,&nbsp;iš&nbsp;kurio&nbsp;parsinam&nbsp;įrašus&nbsp;(-ą)  <br />
</span><span style="color: rgb(0, 0, 187);">$blogUrl&nbsp;</span><span style="color: rgb(0, 119, 0);">=&nbsp;</span><span style="color: rgb(221, 0, 0);">'http://www.lescinskas.lt/index.php/lt/blog/rss'</span><span style="color: rgb(0, 119, 0);">; <br />
<br />
</span><span style="color: rgb(0, 0, 187);">$parsedUrl&nbsp;</span><span style="color: rgb(0, 119, 0);">=&nbsp;</span><span style="color: rgb(0, 0, 187);">parse_url</span><span style="color: rgb(0, 119, 0);">(</span><span style="color: rgb(0, 0, 187);">$blogUrl</span><span style="color: rgb(0, 119, 0);">); <br />
<br />
</span><span style="color: rgb(255, 128, 0);">//&nbsp;Išparsintas&nbsp;įrašas: <br />
</span><span style="color: rgb(0, 0, 187);">$parsedEntry&nbsp;</span><span style="color: rgb(0, 119, 0);">=&nbsp;</span><span style="color: rgb(0, 0, 187);">preg_replace</span><span style="color: rgb(0, 119, 0);">(</span><span style="color: rgb(221, 0, 0);">'/(&lt;\s*img&nbsp;[^\&gt;]*src\s*=\s*[\&quot;&quot;\']?)(\/[^\&quot;&quot;\'\s&gt;]*)/i'</span><span style="color: rgb(0, 119, 0);">,&nbsp;</span><span style="color: rgb(221, 0, 0);">'\\1'</span><span style="color: rgb(0, 119, 0);">.</span><span style="color: rgb(0, 0, 187);">$parsedUrl</span><span style="color: rgb(0, 119, 0);">[</span><span style="color: rgb(221, 0, 0);">'scheme'</span><span style="color: rgb(0, 119, 0);">].</span><span style="color: rgb(221, 0, 0);">'://'</span><span style="color: rgb(0, 119, 0);">.</span><span style="color: rgb(0, 0, 187);">$parsedUrl</span><span style="color: rgb(0, 119, 0);">[</span><span style="color: rgb(221, 0, 0);">'host'</span><span style="color: rgb(0, 119, 0);">].</span><span style="color: rgb(221, 0, 0);">'\\2'</span><span style="color: rgb(0, 119, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 187);">$blogEntry</span><span style="color: rgb(0, 119, 0);">);  <br />
<br />
echo&nbsp;</span><span style="color: rgb(0, 0, 187);">$parsedEntry</span><span style="color: rgb(0, 119, 0);">; <br />
</span><span style="color: rgb(0, 0, 187);">?&gt; <br />
</span> </span> </code></p>
<p>&nbsp;</p>]]></description>
      <pubDate>Tue, 12 Aug 2008 10:23:07 +0300</pubDate>
      <link>http://www.lescinskas.lt/lt/blog/entry/paulius/iliustraciju-korekcija-rss-agregatoriuose</link>
    </item>
  </channel>
</rss>

