<?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>PHP / MySQL / Linux Stories &#187; php</title>
	<atom:link href="http://xfragger.de/category/php/feed" rel="self" type="application/rss+xml" />
	<link>http://xfragger.de</link>
	<description>Meine Erfahrungen in der Webentwicklerwelt</description>
	<lastBuildDate>Wed, 03 Nov 2010 06:35:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Developers Shame Day 2010</title>
		<link>http://xfragger.de/312/developers-shame-day-2010</link>
		<comments>http://xfragger.de/312/developers-shame-day-2010#comments</comments>
		<pubDate>Wed, 03 Nov 2010 06:35:10 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[developers shame day]]></category>
		<category><![CDATA[devshameday]]></category>

		<guid isPermaLink="false">http://xfragger.de/?p=312</guid>
		<description><![CDATA[PHP hates me Autor Nils nimmt am Developers-Shame-Day 2010 teil und ich dachte mir, ich suche auch mal in den Untiefen meines alten Codes nach einem Schmuckstück. Ursprünglich kam die Idee zum DevShameDay von &#8220;Cem, dem PHP-Hacker&#8220;. Leider ging in den Jahren einiges verloren, aber ich denke, dass hier ist schlecht genug, um sich dafür [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.phphatesme.com/blog/aktuelles/der-developers-shame-day/?utm_source=twitterfeed&#038;utm_medium=twitter&#038;utm_campaign=Feed:+PhpHatesMe-DerPhpBlog+(PHP+hates+me+-+Der+PHP+Blog)">PHP hates me</a> Autor <a href="http://www.phphatesme.com/blog/author/nils/">Nils</a> nimmt am  Developers-Shame-Day 2010 teil und ich dachte mir, ich suche auch mal in den Untiefen meines alten Codes nach einem Schmuckstück. Ursprünglich kam die Idee zum DevShameDay von &#8220;<a href="http://phphacker.net/2010/10/26/der-developers-shame-day/" rel="nofollow">Cem, dem PHP-Hacker</a>&#8220;.<br />
Leider ging in den Jahren einiges verloren, aber ich denke, dass hier ist schlecht genug, um sich dafür zu schämen.</p>
<p>Ich Schätze das ist um 2004 entstanden und lieferte Termine bzw. Events von einem bestimmten Tag, das ganze für einen Webkalender ala Google-Calendar. Was ich noch erwähnen sollte&#8230;. die Funktion wurde für jeden sichtbaren Kalendertag aufgerufen!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">function</span> getevents<span style="color: #009900;">&#40;</span><span style="color: #000088;">$year</span><span style="color: #339933;">,</span><span style="color: #000088;">$month</span><span style="color: #339933;">,</span><span style="color: #000088;">$day</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$SELF</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$month</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'0'</span><span style="color: #339933;">.</span><span style="color: #000088;">$month</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$month</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$day</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$day</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'0'</span><span style="color: #339933;">.</span><span style="color: #000088;">$day</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$day</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$year</span>-<span style="color: #006699; font-weight: bold;">$month</span>-<span style="color: #006699; font-weight: bold;">$day</span>&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$strx</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$month</span>-<span style="color: #006699; font-weight: bold;">$day</span>&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;
           SELECT e.name as ename,
                                                e.description as edescr,
                                                e.id as eid,
                                                t.color as tcolor,
                                                e.time_start as time_start,
                                                e.time_end as time_end,
                                                e.remember as rem,
                                        e.date_start as date_start,
                                                e.date_end as date_end,
                                                t.description as tdescription,
                                                t.showtime as showtime
           FROM cal_entry e, cal_types t
           WHERE e.types_id = t.id
             AND (e.date_start &lt;= '<span style="color: #006699; font-weight: bold;">$str</span>'
                           AND ( e.date_end &gt;= '<span style="color: #006699; font-weight: bold;">$str</span>' AND e.date_end IS NOT NULL OR e.date_start = '<span style="color: #006699; font-weight: bold;">$str</span>' AND e.date_end IS NULL )
         OR(t.id = 1 AND right(e.date_start,5) = '<span style="color: #006699; font-weight: bold;">$strx</span>')
                         )
                        ORDER BY e.time_start, t.prio
         &quot;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;u&gt;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$SELF</span>?show=new&amp;date=<span style="color: #006699; font-weight: bold;">$year</span>-<span style="color: #006699; font-weight: bold;">$month</span>-<span style="color: #006699; font-weight: bold;">$day</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #006699; font-weight: bold;">$day</span>.<span style="color: #006699; font-weight: bold;">$month</span>.&lt;/a&gt;&lt;/u&gt;&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$tmp</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$SELF</span>?show=edit&amp;eid=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;eid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;ym=<span style="color: #006699; font-weight: bold;">$year</span>-<span style="color: #006699; font-weight: bold;">$month</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
                 <span style="color: #000088;">$tmp</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;font class=<span style="color: #000099; font-weight: bold;">\&quot;</span>entry<span style="color: #000099; font-weight: bold;">\&quot;</span> color=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;tcolor&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;li&gt;&quot;</span><span style="color: #339933;">;</span>
                 <span style="color: #000088;">$tmp</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;ename&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                 <span style="color: #000088;">$starta</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;-&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_start&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                 <span style="color: #000088;">$outstart</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$starta</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$starta</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$starta</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;">$enda</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;-&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_end&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                 <span style="color: #000088;">$outend</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$enda</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$enda</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$enda</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;">$divbody</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;table border=0 class=entry&gt;&lt;tr&gt;&quot;</span><span style="color: #339933;">;</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;">&quot;date_end&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_start&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_end&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                   <span style="color: #000088;">$divbody</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;td&gt;Von:&lt;/td&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">$outstart</span>&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Bis:&lt;/td&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">$outend</span>&lt;/td&gt;&lt;/tr&gt;&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: #000088;">$divbody</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;td&gt;Am:&lt;/td&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">$outstart</span>&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
                 <span style="color: #009900;">&#125;</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;">&quot;showtime&quot;</span><span style="color: #009900;">&#93;</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: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_end&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_start&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_end&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;time_end&quot;</span><span style="color: #009900;">&#93;</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;">$divbody</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td&gt;Von:&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;time_start&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; Uhr&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
                             <span style="color: #000088;">$divbody</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td&gt;Bis:&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;time_end&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; Uhr&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
                     <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_start&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_end&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_start&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$str</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;time_start&quot;</span><span style="color: #009900;">&#93;</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;">$divbody</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td&gt;Ab:&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;time_start&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; Uhr&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
                     <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_start&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_end&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_end&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$str</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;time_end&quot;</span><span style="color: #009900;">&#93;</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;">$divbody</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td&gt;Bis:&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;time_end&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; Uhr&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
                     <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_end&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_start&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date_end&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;time_end&quot;</span><span style="color: #009900;">&#93;</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;">$divbody</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td&gt;Ab:&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;time_start&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; Uhr&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
                     <span style="color: #009900;">&#125;</span>
                 <span style="color: #009900;">&#125;</span>
                 <span style="color: #000088;">$rem</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;rem&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;&lt;font color=green&gt;EMail Erinnerung aktiv&lt;/font&gt;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&lt;font color=red&gt;EMail Erinnerung inaktiv&lt;/font&gt;&quot;</span><span style="color: #339933;">;</span>
                 <span style="color: #000088;">$divbody</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/table&gt;&quot;</span><span style="color: #339933;">;</span>
                 <span style="color: #666666; font-style: italic;">#$div = &quot;&lt;div title=\&quot;header=[&quot;.$row[&quot;ename&quot;].&quot;] body=[&quot;.$row[&quot;edescr&quot;].$divbody&quot;]\&quot;&gt;&quot;;
</span>                 <span style="color: #000088;">$div</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;div title=&quot;header=['</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;ename&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'] body=['</span><span style="color: #339933;">.</span><span style="color: #990000;">nl2br</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;edescr&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$divbody</span><span style="color: #339933;">.</span><span style="color: #000088;">$rem</span><span style="color: #339933;">.</span><span style="color: #0000ff;">']&quot;&gt;'</span><span style="color: #339933;">;</span>
                 <span style="color: #000088;">$tmp</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;&lt;/li&gt;&lt;/font&gt;&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
                 <span style="color: #000088;">$out</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$div</span><span style="color: #339933;">.</span><span style="color: #000088;">$tmp</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">return</span> <span style="color: #000088;">$out</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://xfragger.de/312/developers-shame-day-2010/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTML zu PDF umwandeln, endlich &#8220;einfach&#8221; (Plattformunabhängig)</title>
		<link>http://xfragger.de/286/html-zu-pdf-umwandeln-endlich-einfach-plattformunabhangig</link>
		<comments>http://xfragger.de/286/html-zu-pdf-umwandeln-endlich-einfach-plattformunabhangig#comments</comments>
		<pubDate>Sun, 01 Aug 2010 12:47:26 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[html2pdf pdf html koverter]]></category>

		<guid isPermaLink="false">http://xfragger.de/?p=286</guid>
		<description><![CDATA[Mal wieder auf der Suche nach einer sinnvollen HTML2PDF Lösung, bin ich auf wkhtmltopdf gestoßen. Das Tool nutzt Webkit im internen Backend und kann sogar CSS3 rendern. Die Installation unter MaxOSX und Linux ist absolut simpel: runterladen, ablegen, fertig. Unter Windows wird hier noch ein Installationsprozess durchgeführt, über den ich aktuell leider nichts sagen kann [...]]]></description>
			<content:encoded><![CDATA[<p>Mal wieder auf der Suche nach einer sinnvollen HTML2PDF Lösung, bin ich auf <a href="http://code.google.com/p/wkhtmltopdf/" target="_blank">wkhtmltopdf</a> gestoßen.</p>
<p>Das Tool nutzt <a href="http://webkit.org/" target="_blank">Webkit</a> im internen Backend und kann sogar CSS3 rendern. Die Installation unter MaxOSX und Linux ist absolut simpel: runterladen, ablegen, fertig. Unter Windows wird hier noch ein Installationsprozess durchgeführt, über den ich aktuell leider nichts sagen kann (bisher nicht getestet).</p>
<p>Um das Tool auf einer Webseite zu nutzen, habe ich mir ne kleine Klasse geschrieben, die HTML-Code als Input akzeptiert und mir den Pfad der fertigen PDF-Datei zurückliefert.</p>
<p><span id="more-286"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> HtmlToPdf <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">const</span> TMP <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/tmp/'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">const</span> <span style="color: #990000;">EXEC</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/usr/local/bin/wkhtmltopdf-amd64'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//anpassen!</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$executable</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$htmlcode</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$tmphtmlfile</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$targetFilename</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'--ignore-load-errors'</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Kommandozeilenoptionen für wkhtmltopdf</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$targetFilename</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">targetFilename</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$targetFilename</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setHtmlCode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$htmlcode</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><span style="color: #004000;">htmlcode</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$htmlcode</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setTargetFilename<span style="color: #009900;">&#40;</span><span style="color: #000088;">$targetFilename</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><span style="color: #004000;">targetFilename</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$targetFilename</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> generate<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><span style="color: #004000;">createTempHtmlFile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">convertHtmlfileToPdf</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">TMP</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">targetFilename</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createTempHtmlFile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #990000;">tempnam</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">TMP</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">File</span><span style="color: #339933;">::</span><span style="color: #004000;">move</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #000088;">$filename</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.html'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//nötig, damit die Datei als Input akzeptiert wird</span>
		<span style="color: #000088;">$filename</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'.html'</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">htmlcode</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tmphtmlfile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$filename</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> convertHtmlfileToPdf<span style="color: #009900;">&#40;</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">targetFilename</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><span style="color: #004000;">generateTargetFilename</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: #000088;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #990000;">EXEC</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">.</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">options</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tmphtmlfile</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">TMP</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">targetFilename</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">shell_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cmd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">File</span><span style="color: #339933;">::</span><span style="color: #004000;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tmphtmlfile</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;">private</span> <span style="color: #000000; font-weight: bold;">function</span> generateTargetFilename<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><span style="color: #004000;">targetFilename</span> <span style="color: #339933;">=</span> uniqueid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.pdf'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Und so nutzt man das Ganze:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$converter</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HtmlToPdf<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'output.pdf'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$converter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setHtmlCode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$htmlcodeWithCSS</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdfFile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$converter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Sehr praktisch ist es, wenn man eine Templateengine (z.B. Smarty) nutzt, hier kann man erst den kompletten Code generieren und ihn dann via $smarty->fetch() in den Konverter übergeben. Über einen Parameter kann man dann noch dafür sorgen, dass der CSS Style nicht ausgelagert, sondern im head-Block ausgegeben wird, da das Tool sonst nicht damit klarkommt.</p>
]]></content:encoded>
			<wfw:commentRss>http://xfragger.de/286/html-zu-pdf-umwandeln-endlich-einfach-plattformunabhangig/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP 5.3 DateTime Objekt &#8211; schwerwiegender Bug?</title>
		<link>http://xfragger.de/275/php-5-3-datetime-objekt-schwerwiegender-bug</link>
		<comments>http://xfragger.de/275/php-5-3-datetime-objekt-schwerwiegender-bug#comments</comments>
		<pubDate>Wed, 14 Jul 2010 20:14:29 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[zenddate]]></category>

		<guid isPermaLink="false">http://xfragger.de/?p=275</guid>
		<description><![CDATA[Eigentlich war ich ziemlich begeistert, vom DateTime Objekt. Endlich richtig einfach mit Daten umgehen und das auch noch inkl Zeitzonen etc. Seitdem ich allerdings mit einem Kollegen einen wirklich &#8220;krassen&#8221; Bug fand, bin ich nicht mehr so begeistert! Reproduzierbar ist er folgendermaßen: $from = new DateTime&#40;&#41;; $from-&#62;setTime&#40;0, 0, 0&#41;; $from-&#62;setISODate&#40;2010, 28, 1&#41;; //Montag der 28ten [...]]]></description>
			<content:encoded><![CDATA[<p>Eigentlich war ich ziemlich begeistert, vom <a href="http://de.php.net/manual/de/class.datetime.php" target="_blank">DateTime Objekt</a>. Endlich richtig einfach mit Daten umgehen und das auch noch inkl Zeitzonen etc.<br />
Seitdem ich allerdings mit einem Kollegen einen wirklich &#8220;krassen&#8221; Bug fand, bin ich nicht mehr so begeistert!</p>
<p>Reproduzierbar ist er folgendermaßen:<br />
<span id="more-275"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$from</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DateTime<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$from</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$from</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setISODate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2010</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">28</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: #666666; font-style: italic;">//Montag der 28ten Woche 2010</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$from</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d.m.Y H:i'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//A</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$from</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTimestamp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//B</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d H:i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$from</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTimestamp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//C</span></pre></div></div>

<p>A: das ausgegeben Datum stimmt, es ist der 12.07.2010<br />
B: der Timestamp ist viel zu hoch: 1291849200<br />
C: der Beweis, der Timestamp gehört zum 29.05.2011 00:00</p>
<p>Wir haben lange versucht herauszufinden, warum dies passiert. Ein hässlicher Workaround ist dieser:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$from</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> DateInterval<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'P0D'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Wir fügen also ein Interval von 0 Tagen (oder Stunden, Minuten etc) hinzu, wodurch sich eigentlich nichts ändern sollte. Danach stimmt das Ergebnis von ->getTimestamp() allerdings, nämlich 1278885600. </p>
<p>Nachdem wir absolut keinen Grund feststellen konnten, haben wir das Vertrauen verloren und nutzen seitdem <a href="http://zendframework.com/manual/de/zend.date.html" target="_blank">Zend_Date</a>, welches, meiner Meinung nach, besser und einfacher zu bedienen ist. Das ZendFramework ist sowieso schon im aktuellen Projekt eingebunden (nicht als Framework an sich, eher als Klassensammlung), als sprach es auch nicht dagegen, einen riesen Klotz an Dateien/Klassen zu integrieren, um nur eine Klasse zu nutzen.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$date</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWeek</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">28</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setYear</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2010</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWeekday</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$date</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setHour</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMinute</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setSecond</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$date</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTimestamp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Liefert das erwartete Ergebnis: 1278885600</p>
<p>Ist das nun wirklich ein riesen DateTime Bug oder liegt ein Denkfehler unsererseits vor?</p>
]]></content:encoded>
			<wfw:commentRss>http://xfragger.de/275/php-5-3-datetime-objekt-schwerwiegender-bug/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Iterator oder IteratorAggregated Interface nutzen?</title>
		<link>http://xfragger.de/266/iterator-oder-iteratoraggregated-interface-nutzen</link>
		<comments>http://xfragger.de/266/iterator-oder-iteratoraggregated-interface-nutzen#comments</comments>
		<pubDate>Mon, 28 Jun 2010 20:30:56 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[arrayiterator]]></category>
		<category><![CDATA[iterator]]></category>
		<category><![CDATA[iteratoraggregate]]></category>
		<category><![CDATA[traversable]]></category>

		<guid isPermaLink="false">http://xfragger.de/?p=266</guid>
		<description><![CDATA[PHP bietet das Iterator Interface an, um Objekte direkt via foreach zu iterieren. class MyClass implements Interator &#123; private $array; &#125; &#160; $obj = new MyClass&#40;&#41;; foreach&#40;$obj as $key =&#62; $val&#41;&#123; ... &#125; Damit dieses Konstrukt funktioniert, benötigt die Klasse &#8220;MyClass&#8221; ein paar weitere Methoden und ein Attribut, welche vom Interface vorgeschrieben werden: public function [...]]]></description>
			<content:encoded><![CDATA[<p>PHP bietet das <a href="http://de.php.net/manual/de/class.iterator.php" target="_blank">Iterator</a> Interface an, um Objekte direkt via foreach zu iterieren.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyClass implements Interator <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$array</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$obj</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #339933;">...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-266"></span><br />
Damit dieses Konstrukt funktioniert, benötigt die Klasse &#8220;MyClass&#8221; ein paar weitere Methoden und ein Attribut, welche vom Interface vorgeschrieben werden:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">rewind</span><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><span style="color: #004000;">pointer</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">current</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pointer</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;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">key</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pointer</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">next</span><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><span style="color: #004000;">pointer</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> valid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pointer</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Nun geht das ganze aber auch viel einfacher und mit saubererem Code, mit dem <a href="http://de.php.net/manual/de/class.iteratoraggregate.php" target="_blank">IteratorAggregate</a> Interface und einem <a href="http://de.php.net/manual/de/spl.iterators.php" target="_blank">schon vorhandenem Iterator</a> (wie dem <a href="http://de.php.net/manual/de/class.arrayiterator.php" target="_blank">ArrayIterator</a>). Das Interface ist ziemlich Ähnlich und implementiert ebenfalls <a href="http://de.php.net/manual/de/class.traversable.php" target="_blank">Traversable</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyClass implements IteratorAggregate <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$array</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getIterator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayIterator<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$obj</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #339933;">...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://xfragger.de/266/iterator-oder-iteratoraggregated-interface-nutzen/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WordPress 3 MU auf lighttpd und das &#8220;langsame Bilder&#8221;-Problem</title>
		<link>http://xfragger.de/257/wordpress-3-mu-auf-lighttpd-und-das-langsame-bilder-problem</link>
		<comments>http://xfragger.de/257/wordpress-3-mu-auf-lighttpd-und-das-langsame-bilder-problem#comments</comments>
		<pubDate>Fri, 25 Jun 2010 19:32:54 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Webserver]]></category>
		<category><![CDATA[blogs.php]]></category>
		<category><![CDATA[langsam]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[ms-files.php]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress 3]]></category>
		<category><![CDATA[wordpress mu]]></category>

		<guid isPermaLink="false">http://xfragger.de/?p=257</guid>
		<description><![CDATA[Dieser und der ein oder andere Blog, welche hauptsächlich von meiner Frau betrieben werden, läuft nun auf WordPress 3, weil es mir auf den Geist ging immer x Blogs aktuell zu halten, laufen nun alle mit aktiviertem MU. Da auf meinem Websever lighttpd und nicht apache läuft, konnte ich mich nicht 100%ig an die Anleitung [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://xfragger.de/wp-content/uploads/2010/06/wordpress-300x299.png" rel="lightbox[257]"><img class="alignleft size-thumbnail wp-image-259" title="wordpress-300x299" src="http://xfragger.de/wp-content/uploads/2010/06/wordpress-300x299-150x150.png" alt="" width="150" height="150" /></a>Dieser und der ein oder andere Blog, welche hauptsächlich von meiner Frau betrieben werden, läuft nun auf WordPress 3, weil es mir auf den Geist ging immer x Blogs aktuell zu halten, laufen nun alle mit aktiviertem MU.</p>
<p>Da auf meinem Websever lighttpd und nicht apache läuft, konnte ich mich nicht 100%ig an die Anleitung auf der WP MU Seite halten.</p>
<p><span id="more-257"></span>In lighttpd gibt es kein .htaccess, also müssen die Rewriteregeln (ich nutze Subdomains, keine Unterverzeichnisse), in die lighttpd-config. Das ganze sieht so aus:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$HTTP</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;host&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>~ <span style="color: #0000ff;">&quot;^((.*).?example\.de)$&quot;</span> <span style="color: #009900;">&#123;</span>
  server<span style="color: #339933;">.</span>document<span style="color: #339933;">-</span>root <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/var/www/.../wp3/&quot;</span>
  server<span style="color: #339933;">.</span>error<span style="color: #339933;">-</span>handler<span style="color: #339933;">-</span><span style="color: #cc66cc;">404</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/index.php&quot;</span>  <span style="color: #666666; font-style: italic;">#hierdurch erspart man sich rewrite regeln für schöne permalinks
</span>  url<span style="color: #339933;">.</span>rewrite<span style="color: #339933;">-</span>once <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">&quot;^/(.*/)?files/$&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;/index.php&quot;</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">&quot;^/(.*/)?files/(.*)&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;/wp-content/blogs.php?file=<span style="color: #006699; font-weight: bold;">$2</span>&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">&quot;^/([_0-9a-zA-Z-]+/)?(wp-.*)&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;/<span style="color: #006699; font-weight: bold;">$2</span>&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">&quot;^/([_0-9a-zA-Z-]+/)?(.*\.php)$&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;/<span style="color: #006699; font-weight: bold;">$2</span>&quot;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Der Rest lief einwandfrei nach offizieller Anleitung, da in einigen der anderen Blogs allerdings recht viele Bilder sind, viel mir sofort die mangelnde Performance diesbezüglich auf. Der Grund war schnell gefunden, gab es 40 Bilder auf einer Seite, bedeutete dies, aufgrund der zweiten Rewriteregel, jeweils einen Aufruf eines PHP Skriptes, welches einen ganzen Schweif an includes inkl. Datenbankverbindungen und Queries mit sich bringt.</p>
<p>Die Lösung war, mit ein wenig Linuxwissen, aber schnell gefunden: Symlinks für jeden einzelnen Blog. Erfordert zwar ein wenig mehr Verwaltungsaufwand, spart aber das Umleiten über ein PHP Skript, um Bilder anzuzeigen. Die Regel muss dann so aussehen:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #0000ff;">&quot;^/(.*/)?files/(.*)$&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;/wp-content/blogs.dir/%0/files/<span style="color: #006699; font-weight: bold;">$2</span>&quot;</span><span style="color: #339933;">,</span></pre></div></div>

<p>Das %0 funktioniert so nur, weil die Hostdefinition (Zeile 1 im oberen Code) als Pattern definiert ist!</p>
<p>Im, laut Anleitung angelegten, blogs.dir Verzeichnis müssen nun Symlinks angelegt werden:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">ln <span style="color: #339933;">-</span>s <span style="color: #339933;">/</span><span style="color: #000000; font-weight: bold;">var</span><span style="color: #339933;">/</span>www<span style="color: #339933;">/.../</span>wp3<span style="color: #339933;">/</span>wp<span style="color: #339933;">-</span>content<span style="color: #339933;">/</span>blogs<span style="color: #339933;">.</span><span style="color: #990000;">dir</span><span style="color: #339933;">/</span><span style="color: #009900;">&#91;</span>BlogID<span style="color: #009900;">&#93;</span> <span style="color: #339933;">/</span><span style="color: #000000; font-weight: bold;">var</span><span style="color: #339933;">/</span>www<span style="color: #339933;">/.../</span>wp3<span style="color: #339933;">/</span>wp<span style="color: #339933;">-</span>content<span style="color: #339933;">/</span>blogs<span style="color: #339933;">.</span><span style="color: #990000;">dir</span><span style="color: #339933;">/</span><span style="color: #009900;">&#91;</span>subdomain<span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span>example<span style="color: #339933;">.</span>de</pre></div></div>

<p>Falls jemand eine elegantere Lösung kennt, als für jeden Blog einen Symlink anzulegen, als her damit!</p>
]]></content:encoded>
			<wfw:commentRss>http://xfragger.de/257/wordpress-3-mu-auf-lighttpd-und-das-langsame-bilder-problem/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Haystack und Needle vertauschen &#8211; Wer kennts nicht?</title>
		<link>http://xfragger.de/240/haystack-und-needle-vertauschen-wer-kennts-nicht</link>
		<comments>http://xfragger.de/240/haystack-und-needle-vertauschen-wer-kennts-nicht#comments</comments>
		<pubDate>Sat, 20 Mar 2010 11:06:46 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[haystack]]></category>
		<category><![CDATA[needle]]></category>

		<guid isPermaLink="false">http://blog.xfragger.de/?p=240</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://xfragger.de/wp-content/uploads/2010/03/nedle-und-haystack.jpg" rel="lightbox[240]"><img class="aligncenter size-full wp-image-241" src="http://xfragger.de/wp-content/uploads/2010/03/nedle-und-haystack.jpg" alt="" width="600" height="848" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://xfragger.de/240/haystack-und-needle-vertauschen-wer-kennts-nicht/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Werteingabe (Geld) in gültiges Float umwandeln</title>
		<link>http://xfragger.de/231/werteingabe-geld-in-gultiges-float-umwandeln</link>
		<comments>http://xfragger.de/231/werteingabe-geld-in-gultiges-float-umwandeln#comments</comments>
		<pubDate>Mon, 22 Feb 2010 21:31:39 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[float]]></category>
		<category><![CDATA[geld]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[money]]></category>

		<guid isPermaLink="false">http://blog.xfragger.de/?p=231</guid>
		<description><![CDATA[Jeder hat seine eigene Art einen Geldbetrag einzugeben, der eine gibt 11,99 ein, der nächste 11.99. Weiter geht es mit den 1000er Trennzeichen, spätestens, wenn das System auch auf die amerikanische Schreibweise können soll, brauchen wir eine Methode, die jegliche Eingabe in einen gültigen Float-Wert umwandelt, am besten auch noch richtig. Nach langem hin und [...]]]></description>
			<content:encoded><![CDATA[<p>Jeder hat seine eigene Art einen Geldbetrag einzugeben, der eine gibt 11,99 ein, der nächste 11.99. Weiter geht es mit den 1000er Trennzeichen, spätestens, wenn das System auch auf die amerikanische Schreibweise können soll, brauchen wir eine Methode, die jegliche Eingabe in einen gültigen Float-Wert umwandelt, am besten auch noch richtig.</p>
<p>Nach langem hin und her und viel Recherche habe ich mir aus diversen Codefragmenten das hier zusammengebaut und es scheint zu funktionieren:<span id="more-231"></span></p>
<pre>	function price2float($string){
	    $string = trim($string);
		if(preg_match('/([0-9\.,-]+)/', $string, $matches)){
			// Zahl gefunden also können wir weitermachen
			$string = $matches[0];

			if(preg_match('/^[0-9.-\s]*[\,]{1}[0-9-]{0,2}$/', $string)){
				// Komma als Dezimal Separator
				// Alle Punkte entfernen und anschließend das Komma in einen Punkt umwandeln
				$string = str_replace(' ', '', $string);
				$string = str_replace('.', '', $string);
				$string = str_replace(',', '.', $string);
				return floatval($string);
			}
			elseif(preg_match('/^[0-9,-\s]*[\.]{1}[0-9-]{0,2}$/', $string)){
				// Punkt als Dezimal Separator
				// Alle Kommata entfernen
				$string = str_replace(' ', '', $string);
				$string = str_replace(',', '', $string);
				return floatval($string);
			}
			elseif(preg_match('/^[0-9.-\s]*[\.]{1}[0-9-]{0,3}$/', $string)){
				// Es gibt nur Tausender Separatoren
				// Alle Punkte enfernen
				$string = str_replace(' ', '', $string);
				$string = str_replace('.', '', $string);
				return floatval($string);
			}
			elseif(preg_match('/^[0-9,-\s]*[\,]{1}[0-9-]{0,3}$/', $string)){
				// Es gibt nur Tausender Separatoren
				// Alle Kommata enfernen
				$string = str_replace(' ', '', $string);
				$string = str_replace(',', '', $string);
				return floatval($string);
			}
			else{
				return floatval($string);
			}
		}
		else{
			return 0;
		}
	}
</pre>
<p>Beispiele zum selbsttesten:<br />
1234.456,78 =&gt; 123456.78<br />
1234,456.78 =&gt; 123456.78<br />
12.34 =&gt; 12.34<br />
12,34 =&gt; 12.34<br />
123.456.789 =&gt;  123456789<br />
123,456,789 =&gt; 123456789</p>
<p>wie immer bin ich für Verbesserungsvorschläge offen!</p>
]]></content:encoded>
			<wfw:commentRss>http://xfragger.de/231/werteingabe-geld-in-gultiges-float-umwandeln/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP-Linkfetcher</title>
		<link>http://xfragger.de/226/php-linkfetcher</link>
		<comments>http://xfragger.de/226/php-linkfetcher#comments</comments>
		<pubDate>Sun, 31 Jan 2010 20:26:46 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[php-linkfetcher googlecode facebook]]></category>

		<guid isPermaLink="false">http://blog.xfragger.de/?p=226</guid>
		<description><![CDATA[Hatte die letzten Tage mal die Zeit gefunden, ein kleines, kurzes Projekt zu starten. Ziel ist es, die Facebook-funktionialität abzubilden, die man sieht, wenn man einen Link auf seine Pinnwand posten will. Man erhält eine Auswahl von Vorschaubildern, den Seitentitel, sowie einen kurzen Auszug oder die Seitenbeschreibung. Bei speziellen Links, z.B. youtube oder flickr, gibts [...]]]></description>
			<content:encoded><![CDATA[<p>Hatte die letzten Tage mal die Zeit gefunden, ein kleines, kurzes Projekt zu starten.<br />
Ziel ist es, die Facebook-funktionialität abzubilden, die man sieht, wenn man einen Link auf seine Pinnwand posten will.<br />
Man erhält eine Auswahl von Vorschaubildern, den Seitentitel, sowie einen kurzen Auszug oder die Seitenbeschreibung.<br />
Bei speziellen Links, z.B. youtube oder flickr, gibts dann Vorschaubilder etc.</p>
<p>Meine kleine Bibliothek ist auf GoogleCode zu finden: <a href="http://code.google.com/p/phplinkfetcher/" target="_blank">http://code.google.com/p/phplinkfetcher/</a></p>
<p>Einige &#8220;Fetcher&#8221;-Klassen sind bereits dabei, würde mich aber noch über weitere freuen. Ideen und Verbesserungsvorschläge<br />
in Form von Code oder Kritik ist auch jederzeit erwünscht, einfach hier kommentieren oder den Issue-Tracker von Google nutzen.</p>
]]></content:encoded>
			<wfw:commentRss>http://xfragger.de/226/php-linkfetcher/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Objekte serialisiert in einer MySQL Datenbank ablegen</title>
		<link>http://xfragger.de/223/objekte-serialisiert-in-einer-mysql-datenbank-ablegen</link>
		<comments>http://xfragger.de/223/objekte-serialisiert-in-einer-mysql-datenbank-ablegen#comments</comments>
		<pubDate>Fri, 22 Jan 2010 15:46:14 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[serialize]]></category>

		<guid isPermaLink="false">http://blog.xfragger.de/?p=223</guid>
		<description><![CDATA[Die Meinungen, ob man komplette Objekte ablegen sollte oder nicht, gehen sehr auseinander. Dagegen spricht zum Beispiel, dass man nicht mehr nach Inhalten in einem Objekt suchen kann oder immer der komplette Text neugeschrieben werden muss, auch wenn man nur eine Zahl ändert. Dafür spricht auch einiges, jedenfalls geht es mir darum, dass ich heute [...]]]></description>
			<content:encoded><![CDATA[<p>Die Meinungen, ob man komplette Objekte ablegen sollte oder nicht, gehen sehr auseinander.<br />
Dagegen spricht zum Beispiel, dass man nicht mehr nach Inhalten in einem Objekt suchen kann oder immer der komplette Text neugeschrieben werden muss, auch wenn man nur eine Zahl ändert. Dafür spricht auch einiges, jedenfalls geht es mir darum, dass ich heute vor einem Problem stand.<br />
<span id="more-223"></span><br />
Folgendes Konstrukt habe ich serialisiert (mittels serialize), in ein utf8-unicode-ci TEXT Feld gespeichert. Nach dem auslesen beschwerte sich unserialize über ungültige Daten und mit dem Objekt war nichts mehr anzufangen.</p>
<pre>
class Address {
  /*diverse Properties, hauptsächlich Strings*/
}
class MethodSpecial extends Method {
  /*diverse andere Properties*/
}
abtract class Method {
  protected $address;
  public function setAddress(Address $address){
    $this-&gt;address = $address;
  }
}

$address = new Address(.....);
$method = new SpecialMethod(....);
$method-&gt;setAddress($address);

$string = serialize($method);
</pre>
<p>Gibt man $string mit einem einfachen echo aus, fällt auf, dass hier komische Sonderzeichen vorhanden sind, speichert man das ganze in ein TEXT Feld in einer Tabelle, werden aus diesen Zeichen Sternchen. Das unserialize schlägt fehl.</p>
<p>Nun gibt es zwei Ansätze, dieses Problem zu lösen:<br />
1. base64_encode und base64_decode: einfach den String vorher kodieren und dann speichern, beim auslesen dann erst dekodieren und danach deserialisieren.<br />
2. GLOB bzw. BLOB statt TEXT als Feldtyp nutzen (nicht von mir getestet, der Tip wurde mit von einem Bekannten gegeben)</p>
]]></content:encoded>
			<wfw:commentRss>http://xfragger.de/223/objekte-serialisiert-in-einer-mysql-datenbank-ablegen/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP Codesniffer für Eclipse</title>
		<link>http://xfragger.de/209/php-codesniffer-fur-eclipse</link>
		<comments>http://xfragger.de/209/php-codesniffer-fur-eclipse#comments</comments>
		<pubDate>Sat, 16 Jan 2010 10:35:26 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[codesniffer]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[php code sniffer]]></category>
		<category><![CDATA[pti]]></category>

		<guid isPermaLink="false">http://blog.xfragger.de/?p=209</guid>
		<description><![CDATA[PHP Codesniffer ist ein in PHP geschriebens Tool, welches PHP Code analysieren kann und Verstöße gegen Programmierrichtlinien meldet. PHP Tool Integration (PTI) ist ein Eclipseplugin, welches es ermöglicht, den Codesniffer direkt als Codevalidator zu verwenden, wodurch die Fehler direkt während der Entwicklung schon in Form von Warnings oder Errors angezeigt werden. Installiert wird der Codesniffer [...]]]></description>
			<content:encoded><![CDATA[<p>PHP Codesniffer ist ein in PHP geschriebens Tool, welches PHP Code analysieren kann und Verstöße gegen Programmierrichtlinien meldet. PHP Tool Integration (PTI) ist ein Eclipseplugin, welches es ermöglicht, den Codesniffer direkt als Codevalidator zu verwenden, wodurch die Fehler direkt während der Entwicklung schon in Form von Warnings oder Errors angezeigt werden.<br />
<span id="more-209"></span></p>
<p>Installiert wird der Codesniffer über den Updatemanager (Help -&gt; Install New Software&#8230;), hier die Update-URL &#8220;http://www.phpsrc.org/eclipse/pti/&#8221; eintragen und den Sniffer, sowie wahlweise auch PHPUnit installieren. In den globalen Einstellungen kann man nun einen Standard wählen, Zend und PEAR sind relativ strikt, General enthält typische Regeln, ich habe mich allerdings entschieden, mir aus den vorhandenen Regeln einen eigenen Standard zu erstellen.</p>
<p><strong>Aber zuerst zur Konfiguration:</strong><a href="http://xfragger.de/wp-content/uploads/2010/01/Preferences.png" rel="lightbox[209]"><img class="size-full wp-image-210 alignnone" src="http://xfragger.de/wp-content/uploads/2010/01/Preferences.png" alt="" width="506" height="605" /><br />
</a>Oben wird eine lokal installierte PHP Binary gewählt werden, darunter wählt man optional eine PEAR Bibliothek, &lt;internal&gt; wird mitgeliefert und reicht völlig aus. Während man sich einen eigenen Standard zusammenstellt oder nicht nachvollziehen kann, welche Regel einen bestimmten Fehler wirft, empfiehlt es sich den Debugmodus zu aktivieren. Darunter sind nun die vordefinierten Standards zu finden, hier wählen wir später unseren Standard als &#8220;default&#8221;, aktuell existiert dieser aber noch nicht. Unten sollte man nur noch einstellen, wie breit ein Tab ist und bestätigt erst einmal mit OK.</p>
<p>Testen kann man das ganze nun mit dem Generic-Standard, indem man einen Ordner, ein Projekt oder eine Datei im Navigator wählt und im Kontextmenü unter dem Punkt &#8220;PHP Tools&#8221; den &#8220;PHP Code Sniffer&#8221; klickt. Hat man in den Einstellungen den entsprechenden Validator aktiviert, muss man eine geöffnete Datei nur speichern oder explizit validieren.</p>
<p><a href="http://xfragger.de/wp-content/uploads/2010/01/PHP-01_xfragger_fun_index.php-Eclipse-_Users_fragger_Documents_workspace_galileo.png" rel="lightbox[209]"><img class="size-full wp-image-211 alignnone" src="http://xfragger.de/wp-content/uploads/2010/01/PHP-01_xfragger_fun_index.php-Eclipse-_Users_fragger_Documents_workspace_galileo.png" alt="" width="609" height="605" /><br />
</a>Im Quelltext werden nun &#8220;Fehler&#8221; markiert:<br />
<a href="http://xfragger.de/wp-content/uploads/2010/01/PHP-01_xfragger_fun_index.php-Eclipse-_Users_fragger_Documents_workspace_galileo-1.png" rel="lightbox[209]"><img class="size-full wp-image-212 alignnone" src="http://xfragger.de/wp-content/uploads/2010/01/PHP-01_xfragger_fun_index.php-Eclipse-_Users_fragger_Documents_workspace_galileo-1.png" alt="" width="420" height="105" /><br />
</a>Eine der gesetzten Regeln besagt, dass ein String nicht in double quotes eingeschlossen sein darf, falls dies nicht unbedingt nötig ist (Nötig wäre es z.B. bei einem manuellen Zeilenumbruch im String). Nachdem man nun die double quotes gegen quotes getauscht hat und die Datei gespeichert hat, verschwindet der Fehler.</p>
<p><strong>Erstellen eines eigenen Standards:</strong></p>
<p>Den Pfad zu den Standards musste ich selbst auch erst suchen, er ist tief im plugins Verzeichnis von Eclipse versteckt:</p>
<pre>/plugins/org.phpsrc.eclipse.pti.library.pear_1.1.1.R20091122000100/php/library/PEAR/PHP/CodeSniffer/Standards</pre>
<p>Die Verzeichnisstruktur sieht hier folgendermaßen aus (daran muss sich gehalten werden, wenn der eigene Standard funktionieren soll, da hier mit autoload gearbeitet wird!).<br />
<a href="http://xfragger.de/wp-content/uploads/2010/01/PHP-01_xfragger_fun_index.php-Eclipse-_Users_fragger_Documents_workspace_galileo-2.png" rel="lightbox[209]"><img class="size-full wp-image-213 alignnone" src="http://xfragger.de/wp-content/uploads/2010/01/PHP-01_xfragger_fun_index.php-Eclipse-_Users_fragger_Documents_workspace_galileo-2.png" alt="" width="280" height="576" /></a></p>
<div style="clear:both"></div>
<p>Als Vorlage nehmen wir den Zend-Standard und kopieren erstmal das Verzeichnis nach MyStandard, das Unterverzeichnis Sniffs (so werden einzelne Regeln bezeichnet) solle bestehen bleiben, den Inhalt können wir jedoch erst einmal löschen. Die Datei ZendCodingStandard.php wird umbenannt in MyStandardCodingStandard.php und der Inhalt angepasst, in Zeile 33 muss der Klassenname stimmen, aus</p>
<pre>class PHP_CodeSniffer_Standards_Zend_ZendCodingStandard extends PHP_CodeSniffer_Standards_CodingStandard{</pre>
<p>wird</p>
<pre>class PHP_CodeSniffer_Standards_MyStandard_MyStandardCodingStandard extends PHP_CodeSniffer_Standards_CodingStandard</pre>
<p>Nicht vergessen, den Standard in den Einstellungen als &#8220;default&#8221; zu setzen, dies geht entweder global oder pro Projekt, sobald der Ordner erstellt ist.<br />
Nun können weiter unten in der Methode &#8220;getIncludedSniffs()&#8221; vorhandene Regeln aus allen Standards zusammengestellt werden, die Dateinamen sollten aussagekräftig genug sein, ansonsten gibts es eigentlich in allen Sniffs entsprechende Kommentare.</p>
<pre>    public function getIncludedSniffs()
    {
        return array(
                'Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php',
                'Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php',
                'Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php',
                'PEAR/Sniffs/Classes/ClassDeclarationSniff.php',
                'PEAR/Sniffs/ControlStructures/ControlSignatureSniff.php',
                'PEAR/Sniffs/Files/LineEndingsSniff.php',
                'PEAR/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php',
                'PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php',
                'PEAR/Sniffs/Functions/ValidDefaultValueSniff.php',
                'PEAR/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php',
                'Squiz/Sniffs/Functions/GlobalFunctionSniff.php',
               );

    }//end getIncludedSniffs()</pre>
<p>Zusätzlich zu den hier aufgezählten &#8220;externen&#8221; Regeln kann man nun eigene Sniffs erstellen, in dem ein Ordner mit der entsprechenden &#8220;Kategorie&#8221; im Verzeichnis &#8220;Sniffs&#8221; angelegt wird, z.B. &#8220;Array&#8221;, hier muss nun eine PHP Datei angelegt werden, deren Dateiname mit ..Sniff.php enden muss, dieser Sniff wird dann vom CodeSniffer automatisch geladen. Wichtig ist, dass der Klassenname innerhalb der Datei stimmt: Die Datei &#8220;/MyStandard/Sniffs/Arrays/ArrayDeclarationSniff.php&#8221; muss diesen Klassennamen tragen:</p>
<pre>class MyStandard_Sniffs_Arrays_ArrayDeclarationSniff implements PHP_CodeSniffer_Sniff</pre>
<p>Hat man sich seinen Standard zusammengestellt, ist aber mit Details eines bestimmten Sniffs so nicht zufrieden, kopiert man ihn sich einfach in seinen Standard und entfernt ihn aus dem array, in dem die externen Sniffs definiert sind. Zusätzlich passt man noch den Klassennamen an und ändert die entsprechende Stelle im Code.</p>
]]></content:encoded>
			<wfw:commentRss>http://xfragger.de/209/php-codesniffer-fur-eclipse/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

