<?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>Norm 2782 &#187; Flex</title>
	<atom:link href="http://www.norm2782.com/category/programming/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.norm2782.com</link>
	<description>Why are you here?</description>
	<lastBuildDate>Sat, 07 Mar 2009 08:03:50 +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>AMF Server class for WordPress</title>
		<link>http://www.norm2782.com/2009/01/amf-server-class-for-wordpress/</link>
		<comments>http://www.norm2782.com/2009/01/amf-server-class-for-wordpress/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 14:49:42 +0000</pubDate>
		<dc:creator>norm2782</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.norm2782.com/?p=27</guid>
		<description><![CDATA[After browsing through WordPress&#8217; code I quickly found that there&#8217;s no sane way to create AMF support as a WP plugin. At least not for someone who hasn&#8217;t done any old-skool procedural PHP in years. Instead of writing a plugin, I decided to write a standalone server script. It&#8217;s still very basic and currently setup [...]]]></description>
			<content:encoded><![CDATA[<p>After browsing through WordPress&#8217; code I quickly found that there&#8217;s no sane way to create AMF support as a WP plugin. At least not for someone who hasn&#8217;t done any old-skool procedural PHP in years. Instead of writing a plugin, I decided to write a standalone server script. It&#8217;s still very basic and currently setup to work for me. To get it working for your WP setup you should probably make some minor modifications. Click the read more link to check out the code. I&#8217;ve released it under the generous BSD license, so knock yourself out! Use it at your own risk&#8230; I&#8217;m not going to support it. Any updates will be posted in this post. Also, please note that I haven&#8217;t tested it yet. If you access the script directly it should output &#8220;Zend Amf Endpoint&#8221; just fine, but that&#8217;s all I can guarantee at this point <img src='http://www.norm2782.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><span id="more-27"></span></p>
<pre name="code" class="php:nogutter">
&lt;?php
/**
 * BSD LICENSE
 *
 * Copyright (c) 2009, norm2782
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of norm2782 nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY norm2782 ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL norm2782 BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * Set production mode.
 * If set to false, exceptions will bubble through to the Flex frontend
 *
 * @var bool
 */
$production = false;

/**
 * Determine the absolute path of the AMF server
 *
 * @var string
 */
define('ABSPATH', dirname(__FILE__) . '/');

/**
 * One directory below docroot. Your config file and library dir should be here.
 *
 * @var string
 */
define('SUBPATH', dirname(ABSPATH));

/**
 * You should make sure Zend Framework is in your include path
 */
set_include_path(
    implode(PATH_SEPARATOR, array(
        SUBPATH . '/library',
        get_include_path()
    ))
);

/**
 * Include the WordPress config file
 */
$configFile = SUBPATH . '/wp-config.php';

if (!file_exists($configFile)) {
    throw new Exception('WordPress config file was not found!');
}

require_once $configFile;

/**
 * No need to config more stuff from this point on
 */

/**
 * @see Zend_Amf_Server
 */
require_once 'Zend/Amf/Server.php';

/**
 * @see Zend_Db_Adapter_Pdo_Mysql
 */
require_once 'Zend/Db/Adapter/Pdo/Mysql.php';

/**
 * @see Zend_Paginator
 */
require_once 'Zend/Paginator.php';

/**
 * @see Zend_Paginator_Adapter_DbSelect
 */
require_once 'Zend/Paginator/Adapter/DbSelect.php';

/**
 * Simple class to expose wordpress data through AMF
 *
 * @author norm2782
 */
class Wp_Amf_Gateway
{
    /**
     * Database adapter
     *
     * @var Zend_Db_Adapter_Pdo_Mysql
     */
    private $_db = null;

    /**
     * WordPress table prefix
     *
     * @var string
     */
    private $_prefix = null;

    /**
     * Constructor
     *
     * @param array $dbConfig
     * @param string $prefix
     * @return void
     */
    public function __construct(array $dbConfig, $prefix)
    {
        $this-&gt;_db = new Zend_Db_Adapter_Pdo_Mysql($dbConfig);
        $this-&gt;_db-&gt;query('SET NAMES `utf8`');

        $this-&gt;_prefix = $prefix;
    }

    /**
     * Get paginated results for the provided query
     *
     * @param Zend_Db_Select $select
     * @param int $page
     * @param int $itemsPerPage
     * @return array
     */
    private function _getPaginated(Zend_Db_Select $select, $page, $itemsPerPage)
    {
        $paginator = new Zend_Paginator(
            new Zend_Paginator_Adapter_DbSelect($select)
        );

        $paginator-&gt;setCurrentPageNumber($page)
                  -&gt;setItemCountPerPage($itemsPerPage);

        return array(
            'info'  =&gt; $paginator-&gt;getPages(),
            'items' =&gt; $paginator-&gt;getCurrentItems()
        );
    }

    /**
     * Get the comments for the specified post ID
     *
     * @param int $postId
     * @param int $page
     * @param int $itemsPerPage
     * @return array
     */
    public function getCommentsForPost($postId, $page = 1, $itemsPerPage = 10)
    {
        $select = $this-&gt;_db-&gt;select()-&gt;from($this-&gt;_prefix . 'comments')
                                      -&gt;where('comment_post_ID = ?', $postId);

        return $this-&gt;_getPaginated($select, $page, $itemsPerPage);
    }

    /**
     * Get the meta data for the specified post ID
     *
     * @param $postId
     * @return unknown_type
     */
    public function getMetaForPost($postId)
    {
        $select = $this-&gt;_db-&gt;select()-&gt;from($this-&gt;_prefix . 'postmeta')
                                      -&gt;where('post_id = ?', $postId);

        return $this-&gt;_db-&gt;fetchAll($select);
    }

    /**
     * Get a post by specifying its ID
     *
     * @param int $postId
     * @return array
     */
    public function getPost($postId)
    {
        $select = $this-&gt;_db-&gt;select()-&gt;from($this-&gt;_prefix . 'posts')
                                      -&gt;where('ID = ?', $postId);

        return $this-&gt;_db-&gt;fetchOne($select);
    }

    /**
     * Get posts per page
     *
     * @param int $page
     * @param int $itemsPerPage
     * @return array
     */
    public function getPosts($page = 1, $itemsPerPage = 10)
    {
        $select = $this-&gt;_db-&gt;select()-&gt;from($this-&gt;_prefix . 'posts');

        return $this-&gt;_getPaginated($select, $page, $itemsPerPage);
    }
}

/**
 * Pass the values from wp-config.php to the Wp_Amf_Gateway class.
 */
$gateway = new Wp_Amf_Gateway(
    array(
        'host'     =&gt; DB_HOST,
        'username' =&gt; DB_USER,
        'password' =&gt; DB_PASSWORD,
        'dbname'   =&gt; DB_NAME
    ),
    $table_prefix
);

$server = new Zend_Amf_Server();
$server-&gt;setProduction($production)
       -&gt;setClass($gateway)
       -&gt;handle();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.norm2782.com/2009/01/amf-server-class-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flex frontend</title>
		<link>http://www.norm2782.com/2009/01/flex-frontend/</link>
		<comments>http://www.norm2782.com/2009/01/flex-frontend/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 23:29:35 +0000</pubDate>
		<dc:creator>norm2782</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.norm2782.com/?p=22</guid>
		<description><![CDATA[I was planning on writing a quick Flex frontend for this blog, but it appears WordPress only offers the posts themselves as RSS feed. If I get real bored (which I doubt, unfortunately) I&#8217;ll have a look and see if I can create a Zend_AMF plugin for WordPress that allows me to retrieve virtually all [...]]]></description>
			<content:encoded><![CDATA[<p>I was planning on writing a quick Flex frontend for this blog, but it appears WordPress only offers the posts themselves as RSS feed. If I get real bored (which I doubt,  unfortunately) I&#8217;ll have a look and see if I can create a Zend_AMF plugin for WordPress that allows me to retrieve virtually all data from my WordPress install. Would be cool <img src='http://www.norm2782.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.norm2782.com/2009/01/flex-frontend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
