<?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>Joey Rivera &#187; Flash</title>
	<atom:link href="http://www.joeyrivera.com/tag/flash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joeyrivera.com</link>
	<description>Blogging about PHP, Actionscript, MySQL, and other interests.</description>
	<lastBuildDate>Fri, 02 Dec 2011 03:55: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>Uploader Phase 2 complete!</title>
		<link>http://www.joeyrivera.com/2008/uploader-phase-2-complete/</link>
		<comments>http://www.joeyrivera.com/2008/uploader-phase-2-complete/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 03:45:52 +0000</pubDate>
		<dc:creator>Joey</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uploader]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.joeyrivera.com/?p=165</guid>
		<description><![CDATA[So today after work I decided it was about time to start working on phase two of my Uploader tool. Phase two consists of allowing me to drag and drop an image URL into the app so the app can then download the image to a folder in my server, create a thumbnail of this [...]]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignleft" style="width: 157px"><img title="Uploader screen shot" src="/blog_files/96/uploader_ss.gif" alt="Here is a screen shot of the Uploader 0.1.0" width="147" height="172" /><p class="wp-caption-text">Uploader 0.2.0</p></div>
<p>So today after work I decided it was about time to start working on phase two of my Uploader tool. Phase two consists of allowing me to drag and drop an image URL into the app so the app can then download the image to a folder in my server, create a thumbnail of this image, and update the WordPress database with information about the new image. The new image would then show up the next time a person visits my blog. If you notice, there is now a &#8220;Pics of Interest&#8221; section on the sidebar to the right of the page (similar to what people are doing with the flickr plugin). Every time I drag an image URL into the Uploader, the new image thumbnail will show in that area and if you click on the thumbnail you&#8217;ll see the full size image.</p>
<p>It was actually much easier than I originally thought to make this work. Technically, the Uploader already has the drag/drop functionality and already takes in a URL. The only extra <a title="Main.as" href="http://www.joeyrivera.com/blog_files/165/Main.as" target="_blank">AS3 code</a> was a check to see if the URL was an image and if so call the PHP page with a code (I&#8217;m passing &#8211;@IMAGE@&#8211; to know it&#8217;s an image &#8211; it was just the first thing that came to my head) so then PHP knows this URL should be treated as an image not just a URL. If you remember, phase 1 for the Uploader allows a person to drag/drop a URL into the app so it creates a new link under the &#8220;Links of Interest&#8221;.<span id="more-165"></span></p>
<p>Most of the changes were on the PHP end. The file that handles the request from the AIR app now does a check to see if this URL is an image. If so, it has to download the original image to the local server, make a thumbnail copy of it, and finally update the wp_images table (this is a new table I created for this - <a title="MySQL create script" href="http://www.joeyrivera.com/blog_files/165/wp_images.sql" target="_blank">MySQL script</a>) in WordPress. I&#8217;m using two PEAR packages to do this: HTTP_Request and Image_Transform. The same can be done just as easily without them but I like using PEAR on my projects. Here&#8217;s the code that does this (<a title="index.php file as text" href="http://www.joeyrivera.com/blog_files/165/file.txt" target="_blank">file.txt</a>):</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$name</span> == <span class="st0">&#8216;&#8211;@IMAGE@&#8211;&#8217;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">// later use unique names?</span><br />
    <span class="re0">$name</span> = <a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$url</span>, strripos<span class="br0">&#40;</span><span class="re0">$url</span>,<span class="st0">&#8216;/&#8217;</span><span class="br0">&#41;</span> + <span class="nu0">1</span><span class="br0">&#41;</span>;<br />
        <br />
&nbsp; &nbsp; <span class="kw1">require</span> <span class="st0">&#8216;HTTP/Request.php&#8217;</span>;<br />
    <span class="re0">$req</span> = <span class="kw2">new</span> HTTP_Request<span class="br0">&#40;</span><span class="re0">$url</span><span class="br0">&#41;</span>;<br />
    <span class="re0">$req</span>-&gt;<span class="me1">sendRequest</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
    <br />
&nbsp; &nbsp; <span class="re0">$fp</span> = <a href="http://www.php.net/fopen"><span class="kw3">fopen</span></a><span class="br0">&#40;</span><span class="st0">&#8216;images/&#8217;</span>.<span class="re0">$name</span>, <span class="st0">&#8216;w&#8217;</span><span class="br0">&#41;</span>;<br />
    <a href="http://www.php.net/fwrite"><span class="kw3">fwrite</span></a><span class="br0">&#40;</span><span class="re0">$fp</span>, <span class="re0">$req</span>-&gt;<span class="me1">getResponseBody</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp;   <a href="http://www.php.net/fclose"><span class="kw3">fclose</span></a><span class="br0">&#40;</span><span class="re0">$fp</span><span class="br0">&#41;</span>;<br />
    <br />
&nbsp; &nbsp; <span class="co1">// create thumbnail</span><br />
    <span class="kw1">require</span> <span class="st0">&#8216;Image/Transform.php&#8217;</span>;</p>
<p>&nbsp;   <span class="co1">//create transform driver object</span><br />
&nbsp;   <span class="re0">$it</span> = Image_Transform::<span class="me2">factory</span><span class="br0">&#40;</span><span class="st0">&#8216;GD&#8217;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp;   <span class="co1">//load the original file</span><br />
&nbsp;   <span class="re0">$it</span>-&gt;<span class="me1">load</span><span class="br0">&#40;</span><span class="st0">&#8216;images/&#8217;</span>.<span class="re0">$name</span><span class="br0">&#41;</span>;</p>
<p>&nbsp;   <span class="co1">//scale it to 100px</span><br />
&nbsp;   <span class="re0">$it</span>-&gt;<span class="me1">scaleMaxLength</span><span class="br0">&#40;</span><span class="nu0">100</span><span class="br0">&#41;</span>;</p>
<p>&nbsp;   <span class="co1">//save it into a different file</span><br />
&nbsp;   <span class="re0">$tn</span> = <a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$name</span>,<span class="nu0">0</span>,strripos<span class="br0">&#40;</span><span class="re0">$name</span>,<span class="st0">&#8216;.&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="st0">&#8216;-tn.&#8217;</span>.<a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$name</span>,strripos<span class="br0">&#40;</span><span class="re0">$name</span>,<span class="st0">&#8216;.&#8217;</span><span class="br0">&#41;</span><span class="nu0">+1</span><span class="br0">&#41;</span>;<br />
&nbsp;   <span class="re0">$it</span>-&gt;<span class="me1">save</span><span class="br0">&#40;</span><span class="st0">&#8216;images/&#8217;</span>.<span class="re0">$tn</span><span class="br0">&#41;</span>;</p>
<p>&nbsp;   <span class="re0">$query</span> = <span class="st0">&#8216;<br />
&nbsp;           Insert Into wp_images<br />
&nbsp;           Values (null, &#8216;</span>.<span class="re0">$db</span>-&gt;<span class="me1">quote</span><span class="br0">&#40;</span><span class="re0">$name</span>, <span class="st0">&#8216;text&#8217;</span><span class="br0">&#41;</span>.<span class="st0">&#8216;, &#8216;</span>.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$db</span>-&gt;<span class="me1">quote</span><span class="br0">&#40;</span><span class="re0">$tn</span>, <span class="st0">&#8216;text&#8217;</span><span class="br0">&#41;</span>.<span class="st0">&#8216;, &#8216;</span>.<span class="re0">$db</span>-&gt;<span class="me1">quote</span><span class="br0">&#40;</span><span class="re0">$url</span>, <span class="st0">&#8216;text&#8217;</span><span class="br0">&#41;</span>.<span class="st0">&#8216;);<br />
}</span></div>
<p>Then I had to add some code to the sidebar.php for my template in WordPress to show the new section &#8220;Pics of Interest&#8221;. As you read this keep in mind this is just a quick beta and I&#8217;ll be doing refactoring later. This is by no means a finished product but it works fine and it&#8217;s a good start for anyone who wants to try it out. This is the new code I added to my <a title="sidebar.php" href="http://www.joeyrivera.com/blog_files/165/sidebar.txt" target="_blank">sidebar.php</a>:</p>
<div class="dean_ch" style="white-space: wrap;">&lt;div <span class="kw2">class</span>=<span class="st0">&quot;block poi&quot;</span>&gt;<br />
&nbsp;       &lt;h3&gt;Pics of Interest&lt;/h3&gt;<br />
&nbsp;       <span class="kw2">&lt;?php</span><br />
&nbsp;               <span class="kw1">require</span> <span class="st0">&#8216;./uploader/lib/DB.php&#8217;</span>;<br />
&nbsp;               DB::<span class="me2">conn</span><span class="br0">&#40;</span><span class="st0">&#8216;live&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp;               <span class="re0">$db</span> = DB::<span class="me2">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp;               <span class="re0">$query</span> = <span class="st0">&#8216;<br />
&nbsp;                       Select image_file, image_thumbnail, image_origin<br />
&nbsp;                       From wp_images<br />
&nbsp;                       Order By image_id desc<br />
&nbsp;                       Limit 6;<br />
&nbsp;                       &#8217;</span>;</p>
<p>&nbsp;               <span class="re0">$rs</span> = <span class="re0">$db</span>-&gt;<span class="me1">query</span><span class="br0">&#40;</span><span class="re0">$query</span><span class="br0">&#41;</span>;<br />
&nbsp;               <span class="kw1">while</span><span class="br0">&#40;</span><span class="re0">$row</span> = <span class="re0">$rs</span>-&gt;<span class="me1">fetchRow</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/print"><span class="kw3">print</span></a> <span class="st0">&#8216;&lt;a href=&quot;/uploader/images/&#8217;</span>.<span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">&#8216;image_file&#8217;</span><span class="br0">&#93;</span>.<span class="st0">&#8216;&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=&quot;From: &#8216;</span>.<span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">&#8216;image_origin&#8217;</span><span class="br0">&#93;</span>.<span class="st0">&#8216;&quot;&gt;&lt;img<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; src=&quot;/uploader/images/&#8217;</span>.<span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">&#8216;image_thumbnail&#8217;</span><span class="br0">&#93;</span>.<span class="st0">&#8216;&quot; /&gt;&lt;/a&gt;&#8217;</span>;<br />
&nbsp;       <span class="kw2">?&gt;</span><br />
&lt;/div&gt;</div>
<p>The last thing I had to do was to add the style for my images in the styles.css file and I was done. Make sure your images folder has the proper privileges so you can upload an image into it. The next phase will be allowing me to drag files from my local file system into the AIR app so it&#8217;ll upload it to my server. Right now the Uploader only does something when a URL is dropped on it: adds a link if it&#8217;s not a image, adds the image if it&#8217;s an image.</p>
<p>Question, comments, conerns are always welcome!</p>
<p>Edit:</p>
<p><a title="Info about Uploader Phase 1" href="http://www.joeyrivera.com/2008/uploader-phase-1/" target="_self">Uploader Phase 1</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.joeyrivera.com/2008/uploader-phase-2-complete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uploader: Automating WordPress Links and File Uploads</title>
		<link>http://www.joeyrivera.com/2008/uploader-automating-wordpress-links-and-file-uploads/</link>
		<comments>http://www.joeyrivera.com/2008/uploader-automating-wordpress-links-and-file-uploads/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 01:12:41 +0000</pubDate>
		<dc:creator>Joey</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uploader]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wordpress links]]></category>

		<guid isPermaLink="false">http://www.joeyrivera.com/?p=93</guid>
		<description><![CDATA[So now that I&#8217;m starting to get my WordPress and new hosting server settled in I&#8217;m trying to think of what I can create to help me automate some tasks. One of the things I know I&#8217;ll be doing quite often is adding new links to the &#8216;Links of Interest&#8217; on the front page.  I&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>So now that I&#8217;m starting to get my WordPress and new hosting server settled in I&#8217;m trying to think of what I can create to help me automate some tasks. One of the things I know I&#8217;ll be doing quite often is adding new links to the &#8216;Links of Interest&#8217; on the front page.  I&#8217;ll also be uploading files/images to use on posts or to share with others but I&#8217;m too lazy to be ftping files constantly. So&#8230; time for a new tool!</p>
<p>The Uploader (yeah I know, I&#8217;m very creative) is going to do all the above for me. This will be a app I can keep running on my desktop somewhere and when I need to upload a file or link I can just drag it over and drop it in. The tool will then figure out what kind of item was dropped in and what to do with it.</p>
<p>Phase 1 will handle the links. The way the tool should work for links is the following.  I visit a page that I find interesting and want to add to the &#8216;Links of Interest&#8217;.  Instead of logging into WordPress to create it, I highlight the link from the address bar of the browser, drag it over to the app, and drop it. Now the app needs to figure out the &lt;title&gt; of that page to use as the name since we need a name and url to create a link. Once it has that, the tool will send the information to a PHP page which will do an insert to the links table in the WordPress DB.  </p>
<p>Phase 2 will deal with images and files. I may break phase 2 into two since I may do some stuff differently with images versus other files.  I&#8217;m thinking I may want to upload images, create a thumbnail, and insert to a DB to display in the front page the same way some people do with their flickr images. Other files I would just upload and store somewhere else.  I&#8217;ll give this more thought when I get to it.</p>
<p>I&#8217;m going to be writing the tool in Flash CS3/AIR with PHP in the backend using the current WordPress MySQL DB.  Stay tuned for updates!</p>
<p>EDIT:</p>
<p><a title="Uploader Phase 1 done" href="http://www.joeyrivera.com/2008/uploader-phase-1/" target="_self">Uploader Phase 1 completed</a> <br />
<a title="Uploader Phase 2 done" href="http://www.joeyrivera.com/2008/uploader-phase-2-complete/" target="_self"> Uploader Phase 2 completed</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.joeyrivera.com/2008/uploader-automating-wordpress-links-and-file-uploads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

