<?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>BinaryKitten&#039;s Development Dropbox &#187; PHP</title>
	<atom:link href="http://binarykitten.com/category/dev/php/feed" rel="self" type="application/rss+xml" />
	<link>http://binarykitten.com</link>
	<description>Curently a work in progress. Please be patient</description>
	<lastBuildDate>Thu, 27 Oct 2011 21:49:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Don&#8217;t use IsValid in your Doctrine Models &#8211; a warning</title>
		<link>http://binarykitten.com/dev/324-dont-use-isvalid-in-your-doctrine-models-a-warning.html</link>
		<comments>http://binarykitten.com/dev/324-dont-use-isvalid-in-your-doctrine-models-a-warning.html#comments</comments>
		<pubDate>Thu, 09 Sep 2010 10:33:55 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[DB]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://binarykitten.me.uk/?p=324</guid>
		<description><![CDATA[Recently for a project i&#8217;ve been making heavy use of Doctrine. In one of the models I had a method to check to see if the object was valid under a certain set of conditions. I named this function isValid .. and it had 2 params. Little did I know that this was actually overriding [...]]]></description>
			<content:encoded><![CDATA[<p>Recently for a project i&#8217;ve been making heavy use of Doctrine. In one of the models I had a method to check to see if the object was valid under a certain set of conditions. I named this function isValid .. and it had 2 params. Little did I know that this was actually overriding an existing deep rooted isValid which gets fired on saving the object to the DB. Bummer. </p>
<p>So this is a quick warning to all you Doctrine users. Unless you want to actually override the isValid method for saving, call your check method function something else!</p>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.com/dev/324-dont-use-isvalid-in-your-doctrine-models-a-warning.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Chmod-ed to Windows hell and back</title>
		<link>http://binarykitten.com/dev/php/159-php-chmod-ed-to-windows-hell-and-back.html</link>
		<comments>http://binarykitten.com/dev/php/159-php-chmod-ed-to-windows-hell-and-back.html#comments</comments>
		<pubDate>Tue, 10 Mar 2009 21:05:22 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[files]]></category>

		<guid isPermaLink="false">http://binarykitten.jkrswebsolutions.co.uk/?p=159</guid>
		<description><![CDATA[Today has not been a good day. With various things going wrong, I was please that I had got the file upload code done for a site i&#8217;m working on. All I needed to do was make sure that the file had the right permissions and then edit it via GD (via an image editor [...]]]></description>
			<content:encoded><![CDATA[<p>Today has not been a good day.</p>
<p>With various things going wrong, I  was please that I had got the file upload code done for a site i&#8217;m working on. All I needed to do was make sure that the file had the right permissions and then edit it via GD (via an image editor class i have). Here&#8217;s where the trouble started..</p>
<p>I started off by chmoding the file to 777 and then trying to do the resize.. this threw an error with permissions.. so i looked at the file.. Read Only.. strange I thought.</p>
<p>Then I checked the folder and that had a weird green square instead of the checkmark in the checkbox. I tried to remove the read only attribute off of this and hte file.. and it kept coming back.. I went all around hte houses, trying all sorts of techniques .. to no avail.</p>
<p><a href="http://twitter.com/auroraeosrose">@auroraeosrose</a> in the PHPWomen IRC channel helped a lot as did Dreis.. (thanks muchly)..</p>
<p>After backing up the files and formatting the drive, to reinstalling the Apache/PHP/MySql stack I was no clearer to the answer as to why the file was always ending up with read only permissions..</p>
<p>Finally it came down to the 1 thing that I had overlooked.. the <a href="http://php.net/chmod">chmod</a> in the code .. the second parameter was 777. I thought this was correct. Aparrantly not. The second parameter of the chmod function requires an octal code.. thus prefixing the 777 with a 0 (zero) fixed the whole issue.</p>
<p>Boy did i really feel dumb today.</p>
<p>So to wrap up, remember to always pass a FOUR digit code through to chmod or face the annoyance and headache I got today.</p>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.com/dev/php/159-php-chmod-ed-to-windows-hell-and-back.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>php: processing raw Post / Get Values</title>
		<link>http://binarykitten.com/dev/php/95-php-processing-raw-post-get-values.html</link>
		<comments>http://binarykitten.com/dev/php/95-php-processing-raw-post-get-values.html#comments</comments>
		<pubDate>Wed, 21 Jan 2009 09:03:53 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[head]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[raw post]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://binarykitten.jkrswebsolutions.co.uk/?p=95</guid>
		<description><![CDATA[I just added a jquery plugin to call head requests, but because you are not doing a get or post request php won&#8217;t convert the values that are sent back to their form. To get around this we have to use the php://input stream ( is that the right word?) which is handy for a [...]]]></description>
			<content:encoded><![CDATA[<p>I just added a <a href="http://binarykitten.jkrswebsolutions.co.uk/2009/01/21/jquery-plugin-ajax-head-request/">jquery plugin</a> to call head requests, but because you are not doing a get or post request php won&#8217;t convert the values that are sent back to their form.<br />
To get around this we have to use the php://input stream ( is that the right word?) which is handy for a lot of things.</p>
<pre class="brush: php">
$data = file_get_contents(&quot;php://input&quot;);
$lines = explode(&quot;&amp;&quot;,$data);
foreach($lines as $line) {
    list($key,$value) = explode(&quot;=&quot;,$line,2);
    $_REQUEST[$key] = $value;
}
</pre>
<p>basically this grabs the data from the php://input and then splits it up into it&#8217;s component parts and then stores that within the $_REQUEST superglobal array.<br />
Why $_REQUEST  well we&#8217;re calling a head request and not a post or get request, so where else should it go.</p>
<p>The php://input is handy when doing stuff like xmlRPC or jsonRPC etc .. </p>
<p>Hopefully this will benefit someone out there</p>
<p>&lt;edit&gt;<br />
Thanks to Mortal of #php on OFTC (irc) for pointing out the unlimited explode </p>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.com/dev/php/95-php-processing-raw-post-get-values.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php: smarty assign content plugin</title>
		<link>http://binarykitten.com/dev/php/smarty-templates/83-php-smarty-assign-content-plugin.html</link>
		<comments>http://binarykitten.com/dev/php/smarty-templates/83-php-smarty-assign-content-plugin.html#comments</comments>
		<pubDate>Mon, 12 Jan 2009 19:27:18 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[Smarty]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://binarykitten.jkrswebsolutions.co.uk/?p=83</guid>
		<description><![CDATA[I needed to assign a block of content to a variable instead of just a value.. so i set about creating this plugin function smarty_block_assign_content($params, $content, &#38;$smarty) { $smarty = clone($smarty); //Copy the original class, so there&#039;s no garbage variables after we finish if(!isset($content)) return; if (!isset($params[&#039;var&#039;])) { $smarty-&#62;trigger_error(&#34;assign_content: missing &#039;var&#039; parameter&#34;, E_USER_WARNING); return; } [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to assign a block of content to a variable instead of just a value.. so i set about creating this plugin</p>
<pre class="brush: php">
function smarty_block_assign_content($params, $content, &amp;$smarty)
{
        $smarty = clone($smarty); //Copy the original class, so there&#039;s no garbage variables after we finish
        if(!isset($content))
                return;
        if (!isset($params[&#039;var&#039;])) {
                $smarty-&gt;trigger_error(&quot;assign_content: missing &#039;var&#039; parameter&quot;, E_USER_WARNING);
                return;
        }

        //Compile content to ensure all smarty tags get processed
        $smarty-&gt;assign($params[&#039;var&#039;], $content);
                $smarty-&gt;assign($k, $v);
        return ;
}
</pre>
<p>example of usage: </p>
<pre class="brush: html">
{assign_content var=&#039;menu&#039;}
  {foreach from=$menus.cats-&gt;children item=&#039;cat&#039;}
  &lt;div class=&quot;item{if $cat-&gt;active || $cat-&gt;expanded}_select{/if}&quot;&gt;
    &lt;div class=&quot;arrow&quot;&gt;&lt;/div&gt;
    {if !$cat-&gt;active}&lt;a href=&quot;{$cat-&gt;link}&quot;&gt;{/if}{$cat-&gt;text}{if !$cat-&gt;active}&lt;/a&gt;
    {/if}
  &lt;/div&gt;
  {if $cat-&gt;children|<a href="http://twitter.com/count">@count</a> ne 0 || $cat-&gt;expanded}
    {foreach from=$cat-&gt;children item=&#039;subCat&#039;}
      &lt;div class=&quot;subitem{if $subCat-&gt;active}_select{/if}&quot;&gt;
        &lt;div class=&quot;arrow&quot;&gt;&lt;/div&gt;
      {if !$subCat-&gt;active}&lt;a href=&quot;{$subCat-&gt;link}&quot;&gt;{/if}{$subCat-&gt;text}{if !$subCat-&gt;active}&lt;/a&gt;{/if}
      &lt;/div&gt;
    {/foreach}
  {/if}
  {/foreach}
{/assign_content}
</pre>
<p>This will set the code we used to generate the menu and assign it to $menu for later use.<br />
Hope you find as usefull</p>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.com/dev/php/smarty-templates/83-php-smarty-assign-content-plugin.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>php: Menu Classes</title>
		<link>http://binarykitten.com/dev/php/74-php-menu-classes.html</link>
		<comments>http://binarykitten.com/dev/php/74-php-menu-classes.html#comments</comments>
		<pubDate>Mon, 12 Jan 2009 18:52:10 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://binarykitten.jkrswebsolutions.co.uk/?p=74</guid>
		<description><![CDATA[Recently I&#8217;ve been working on my own framework (we&#8217;ve all done it i&#8217;m sure) and part of this was a menu handling system. The basis really is simple, we have a menu item which really is just link and text. That menu item could have children, could be active and/or be selected. In this case [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been working on my own framework (we&#8217;ve all done it i&#8217;m sure) and part of this was a menu handling system.</p>
<p>The basis really is simple, we have a menu item which really is just link and text. That menu item could have children, could be active and/or be selected.</p>
<p>In this case Selected is the currently menu item, which is also Active, and all it&#8217;s parents in the chain upwards are also active.</p>
<p>We also have a menu controller which makes it easier to add to the menus.</p>
<pre class="brush: php">
class menuHandler {
    public $menus=array();
    public function NewMenu() {
        $k = time();
        $this-&gt;menus[$k] = new menu_class();
        return $k;
    }
    public function AddMenu($key,menu_class $menu) {
        if (!isset($this-&gt;menus[$key])) {
            $this-&gt;menus[$key] = $menu;
        }
        return $this;
    }
    public function ItemCount($menuKey) {
        $menu = $this-&gt;menus[$menuKey];
        if (!($menu instanceof menu_class)) {
            return -1;
        }
        else {
            return count($menu-&gt;children);
        }
    }
    public function AddItem($menuKey,$itemKey=null,menu_class $item) {
        if (isset($this-&gt;menus[$menuKey])) {
            $menu = $this-&gt;menus[$menuKey];
            if (!isset($itemKey) or (is_numeric($itemKey) &amp;amp;amp;amp;&amp;amp;amp;amp; $itemKey &lt;0)) {
                $itemKey = count($menu-&gt;children);
            }
            $menu-&gt;AddSubItem($item,$itemKey,$menuKey);
        }
        return $this;
    }
    public function SetActive($id,$from=null) {
        $menu = new menu_class();
        if ($from == null) {
            $from = $this-&gt;menus;
        }
        elseif($from instanceof menu_class) {
            $from = $from-&gt;children;
        }
        foreach ($from as $key=&gt;&amp;amp;amp;amp;$menu) {
            if ($key==$id) {
                $menu-&gt;active=true;
                return true;
            }
            elseif(count($menu-&gt;children) !=0) {
                $r = $this-&gt;SetActive($id,$menu-&gt;children);
                if ($r) {
                    $menu-&gt;expanded = true;
                    return $r;
                }
            }
        }
    }
}
class menu_class {
    public $children = array();
    public $myParent=null;
    public $active = false;
    public $expanded = false;
    public $link =&#039;&#039;;
    public $text = &#039;&#039;;
    public $additional = array();

    public function AddSubItem($item,$ID=null,$parentID=null) {
        if ($item instanceof menu_class) {
        }
        elseif(is_array($item)) {
            $item = new menu_class();
            $item-&gt;text = $details[0];
            $item-&gt;link = $details[1];
        }
        if (isset($ID)) {
            if (isset($this-&gt;children[$ID])) {
                if (is_numeric($ID)) {
                    $this-&gt;children = array_insert($this-&gt;children,$item,$ID);
                }
            }
            else {
                $this-&gt;children[$ID] = $item;
            }
        }
        else {
            $this-&gt;children[] = $item;
        }
        if (!isset($parentID)) {
            $parentID = &quot;main&quot;;
        }
        $this-&gt;myParent = $parentID;
        ksort($this-&gt;children);
    }

    public function __construct($text=null,$link=null) {
        if(isset($text) &amp;amp;amp;amp;&amp;amp;amp;amp; !is_null($text)) {
            $this-&gt;text = $text;
        }
        if(isset($link) &amp;amp;amp;amp;&amp;amp;amp;amp; !is_null($link)) {
            $this-&gt;link = $link;
        }
    } 

    public function Format($text) {
        if (!empty($this-&gt;link)) {
            $text= str_replace(&quot;%href%&quot;,$this-&gt;link);
        }
        if (!empty($this-&gt;text)) {
            $text = str_replace(&quot;%text%&quot;,$this-&gt;text);
        }
        return $text;
    }
}
</pre>
<p>You will notice that i&#8217;ve used the <a href="http://binarykitten.jkrswebsolutions.co.uk/2009/01/11/php-insert-element-and-shift/">array_insert function</a> from my previous posting. This was why it was created, so that i could insert without worry that i would overwrite the code</p>
<p>here&#8217;s an example of using the code</p>
<pre class="brush: php">
$menus = new menuHandler();
$menus-&gt;AddMenu(&quot;main&quot;,new menu_class());
 $menus-&gt;AddItem(&quot;main&quot;,-1,new menu_class(&quot;TEXT&quot;,&quot;link.php&quot;));
 $menus-&gt;AddItem(&quot;main&quot;,-1,new menu_class(&quot;TEXT2&quot;,&quot;link2.php&quot;));
//we want this item to be 1st!
 $menus-&gt;AddItem(&quot;main&quot;,0,new menu_class(&quot;1st Link&quot;,&quot;homelink.php&quot;));
</pre>
<p>So far I pass the $menus out to smarty in the usual assignment method and process like as follows</p>
<pre class="brush: html">
 {foreach from=$menus.main-&gt;children item=&quot;mItem&quot;}
  &lt;div class=&quot;mainbutton&quot;&gt;&lt;a href=&quot;{$mItem-&gt;link}&quot;&gt;{$mItem-&gt;text}&lt;/a&gt;&lt;/div&gt;
 {/foreach}
</pre>
<p>For a cascaded menu i&#8217;ve used the following </p>
<pre class="brush: html">
{foreach from=$menus.cats-&gt;children item=&#039;cat&#039;}
  &lt;div class=&quot;item{if $cat-&gt;active || $cat-&gt;expanded}_select{/if}&quot;&gt;
    &lt;div class=&quot;arrow&quot;&gt;&lt;/div&gt;
    {if !$cat-&gt;active}&lt;a href=&quot;{$cat-&gt;link}&quot;&gt;{/if}{$cat-&gt;text}{if !$cat-&gt;active}&lt;/a&gt;
    {/if}
  &lt;/div&gt;
  {if $cat-&gt;children|<a href="http://twitter.com/count">@count</a> ne 0 || $cat-&gt;expanded}
    {foreach from=$cat-&gt;children item=&#039;subCat&#039;}
      &lt;div class=&quot;subitem{if $subCat-&gt;active}_select{/if}&quot;&gt;
        &lt;div class=&quot;arrow&quot;&gt;&lt;/div&gt;
      {if !$subCat-&gt;active}&lt;a href=&quot;{$subCat-&gt;link}&quot;&gt;{/if}{$subCat-&gt;text}{if !$subCat-&gt;active}&lt;/a&gt;{/if}
      &lt;/div&gt;
    {/foreach}
  {/if}
  {/foreach}
</pre>
<p>As usual any comments gratefully recieved</p>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.com/dev/php/74-php-menu-classes.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php: Insert element at specific Index of Array.</title>
		<link>http://binarykitten.com/dev/php/52-php-insert-element-and-shift.html</link>
		<comments>http://binarykitten.com/dev/php/52-php-insert-element-and-shift.html#comments</comments>
		<pubDate>Sun, 11 Jan 2009 13:41:43 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[insert]]></category>

		<guid isPermaLink="false">http://binarykitten.jkrswebsolutions.co.uk/?p=52</guid>
		<description><![CDATA[In a recent project I&#8217;ve been undertaking I&#8217;ve made a menu class set and sometimes i just wanted to say to add this to an array, but in a certain position. PHP does this easily via $array[position] = &#34;newdata&#34;; But unfortunately this is not so good if you only wanted to insert the newdata into [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent project I&#8217;ve been undertaking I&#8217;ve made a menu class set and sometimes i just wanted to say to add this to an array, but in a certain position. PHP does this easily via</p>
<pre class="brush: php">
$array[position] = &quot;newdata&quot;;
</pre>
<p>But unfortunately this is not so good if you only wanted to insert the newdata into that position and move the others the out of the way. So with a little help from <a title="Derick's Blog" href="http://derickrethans.nl/" target="_blank">Derick Rethans</a> and <a title="Tetraboy's Blog" href="http://www.tetraboy.com" target="_blank">Tetraboy</a> I came up with this little solution.</p>
<p>Any comments gratefully recieved.</p>
<pre>
<pre class="brush: php">
function array_insert(&amp;$array,$element,$position=null) {
  if (count($array) == 0) {
    $array[] = $element;
  }
  elseif (is_numeric($position) &amp;&amp; $position &lt; 0) {
    if((count($array)+position) &lt; 0) {
      $array = array_insert($array,$element,0);
    }
    else {
      $array[count($array)+$position] = $element;
    }
  }
  elseif (is_numeric($position) &amp;&amp; isset($array[$position])) {
    $part1 = array_slice($array,0,$position,true);
    $part2 = array_slice($array,$position,null,true);
    $array = array_merge($part1,array($position=&gt;$element),$part2);
    foreach($array as $key=&gt;$item) {
      if (is_null($item)) {
        unset($array[$key]);
      }
    }
  }
  elseif (is_null($position)) {
    $array[] = $element;
  }
  elseif (!isset($array[$position])) {
    $array[$position] = $element;
  }
  $array = array_merge($array);
  return $array;
}
</pre>
</pre>
<p>and no code would be without it&#8217;s example:</p>
<pre class="brush: php">
// create the array
$x = array(&quot;apples&quot;,&quot;bananas&quot;,&quot;pears&quot;);
//insert &quot;oranges&quot; at position 1
array_insert($x,&quot;oranges&quot;,1);
var_dump($x);
//insert &quot;pineapples&quot; 2 from the end
array_insert($x,&quot;pineapples&quot;,-2);
var_dump($x);
//insert &quot;strawberries&quot; at the end
array_insert($x,&quot;strawberries&quot;);
var_dump($x);
//insert &quot;plums&quot; at position 0 - (because the negative position goes beyond 0)
array_insert($x,&quot;pineapples&quot;,-10);
var_dump($x);
</pre>
<p>or alternatively</p>
<pre class="brush: php">
// create the array
$x = array(&quot;apples&quot;,&quot;bananas&quot;,&quot;pears&quot;);
//insert &quot;oranges&quot; at position 1
$x = array_insert($x,&quot;oranges&quot;,1);
var_dump($x);
//insert &quot;pineapples&quot; 2 from the end
$x = array_insert($x,&quot;pineapples&quot;,-2);
var_dump($x);
//insert &quot;strawberries&quot; at the end
$x = array_insert($x,&quot;strawberries&quot;);
var_dump($x);
//insert &quot;plums&quot; at position 0 - (because the negative position goes beyond 0)
$x = array_insert($x,&quot;plums&quot;,-10);
var_dump($x);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.com/dev/php/52-php-insert-element-and-shift.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

