<?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>SoliTech GmbH &#187; cake</title>
	<atom:link href="http://www.solitechgmbh.com/tag/cake/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.solitechgmbh.com</link>
	<description>Connecting businesses to people through effective online marketing strategy</description>
	<lastBuildDate>Thu, 13 May 2010 19:14:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Updated Random String generator CakePHP component</title>
		<link>http://www.solitechgmbh.com/2009/10/20/updated-random-string-generator-cakephp-component/</link>
		<comments>http://www.solitechgmbh.com/2009/10/20/updated-random-string-generator-cakephp-component/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 04:38:42 +0000</pubDate>
		<dc:creator>Gyuri</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[cake]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.solitechgmbh.com/?p=535</guid>
		<description><![CDATA[Here is a new component that will generate random strings for you. You can pass it a set of characters to pick from and how long your random string should be. I use it to generate passwords but you can do just about anything with it. To use it, create a file called random_helper.php in ...<br /><a href="http://www.solitechgmbh.com/2009/10/20/updated-random-string-generator-cakephp-component/">Read more...</a>]]></description>
			<content:encoded><![CDATA[<p>Here is a new component that will generate random strings for you. You can pass it a set of characters to pick from and how long your random string should be. I use it to generate passwords but you can do just about anything with it.</p>
<p>To use it, create a file called random_helper.php in app/controllers/components and copy the following code.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> RandomHelperComponent <span style="color: #000000; font-weight: bold;">extends</span> Object <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Random string generator function
 *
 * This function will randomly generate a password from a given set of characters
 *
 * @param int = 8, length of the password you want to generate
 * @param string = 0123456789abcdefghijklmnopqrstuvwxyz all possible values
 * @return string, the password
 */</span>     
	<span style="color: #000000; font-weight: bold;">function</span> generateRandomString <span style="color: #009900;">&#40;</span><span style="color: #000088;">$length</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #000088;">$possible</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'0123456789abcdefghijklmnopqrstuvwxyz'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// initialize variables</span>
		<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// add random characters to $password until $length is reached</span>
		<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// pick a random character from the possible ones</span>
			<span style="color: #000088;">$char</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$possible</span><span style="color: #339933;">,</span> <span style="color: #990000;">mt_rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$possible</span><span style="color: #009900;">&#41;</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: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// we don't want this character if it's already in the password</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">strstr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
				<span style="color: #000088;">$password</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$char</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$password</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>make sure you include it in the appcontroller as such</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$components</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Auth'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Email'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'RandomHelper'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>then you can call it as follows in any function</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$password</span><span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">RandomHelper</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateRandomString</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'abcdefghijklmnopqrstuvwxyz'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solitechgmbh.com/2009/10/20/updated-random-string-generator-cakephp-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Bit.ly Class to use with CakePHP or by it self</title>
		<link>http://www.solitechgmbh.com/2009/08/06/new-bit-ly-class-to-use-with-cakephp-or-by-it-self/</link>
		<comments>http://www.solitechgmbh.com/2009/08/06/new-bit-ly-class-to-use-with-cakephp-or-by-it-self/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 23:53:52 +0000</pubDate>
		<dc:creator>Gyuri</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Bit.LY]]></category>
		<category><![CDATA[cake]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.solitechgmbh.com/?p=515</guid>
		<description><![CDATA[If you use service like Twitter where you only get a limited number of characters to post or if you are just sick of dealing with unruly long urls you might be familliar with url shortening services such as Bit.ly. I personally like them because of they offer a nice API and statistics all for ...<br /><a href="http://www.solitechgmbh.com/2009/08/06/new-bit-ly-class-to-use-with-cakephp-or-by-it-self/">Read more...</a>]]></description>
			<content:encoded><![CDATA[<p>If you use service like Twitter where you only get a limited number of characters to post or if you are just sick of dealing with unruly long urls you might be familliar with url shortening services such as Bit.ly.</p>
<p>I personally like them because of they offer a nice API and statistics all for free. It is a pretty quick service too. You can generate hundreds of URLs in just a few seconds. All you have to do is register and you get a username and API key which you will need in the following section.</p>
<p>Here is the code &#8230; As you can see I only implemented the shorten for now but I will probably add some of the other stuff later. For some reason WP won&#8217;t let me post curl_exec( so be sure to remove the extra character.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> bitly <span style="color: #009900;">&#123;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * A PHP class to utilize the bitly API
	 * through the Bitly API. Handles:
	 * - Shorten
	 *
	 * Requires PHP5, CURL, JSON and a Bitly account http://bit.ly/
	 *
	 * Bitly API documentation: http://code.google.com/p/bitly-api/wiki/ApiDocumentation
	 */</span>
&nbsp;
	protected <span style="color: #000088;">$appkey</span><span style="color: #339933;">;</span>
	protected <span style="color: #000088;">$login</span><span style="color: #339933;">;</span>
	protected <span style="color: #000088;">$version</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	* Contruct the Bitly Class
	*
    * @param string, your Bitly account key
    * @param string, your Bitly account login
	*/</span>
	<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;">$login</span><span style="color: #339933;">,</span> <span style="color: #000088;">$appkey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$version</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'2.0.1'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>login <span style="color: #339933;">=</span> <span style="color: #000088;">$login</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>appkey <span style="color: #339933;">=</span> <span style="color: #000088;">$appkey</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>version <span style="color: #339933;">=</span> <span style="color: #000088;">$version</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	* Retrieve a shortened URL
	*
    * @param string, url to shorten
    * @param string, version of Bitly to use
	*/</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> shorten<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//create the URL</span>
		<span style="color: #000088;">$api_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://api.bit.ly/shorten?version='</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>version<span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;amp;longUrl='</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;amp;format=xml&amp;amp;login='</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>login<span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;amp;apiKey='</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>appkey<span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//call the API</span>
		<span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$api_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<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: #000088;">$response</span> <span style="color: #339933;">=</span> curl_ex_ec<span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//parse the XML response and return the url</span>
		<span style="color: #000088;">$xml_object</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleXMLElement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$xml_object</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>results<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>nodeKeyVal<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>shortUrl<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If you want to use this in CakePHP &#8230; you will want to do something like this.<br />
Put this line before the class &#8230; I actually use this in a helper since this is a view level class</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">App<span style="color: #339933;">::</span><span style="color: #004000;">import</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Vendor'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Bitly'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;file&quot;</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">&quot;bitly/bitly.class.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now you can just invoke it in one of your functions somewhere with two simple calls!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$bitly</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Bitly<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'your_API_key_here'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$short_url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bitly</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>shorten<span style="color: #009900;">&#40;</span><span style="color: #000088;">$long_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Simple as that &#8230; oh and one more thing. Be sure to have CURL installed else this won&#8217;t work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solitechgmbh.com/2009/08/06/new-bit-ly-class-to-use-with-cakephp-or-by-it-self/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
