cvs: pear /Services_Blogging/Services/Blogging Driver.php /Services_Blogging/Services/Blogging/Driver Blogger.php LiveJournal.php MetaWeblog.php
| From: | Christian Weiske | Date: | Sun, 10 Feb 2008 18:55:37 +0000 |
| Subject: | cvs: pear /Services_Blogging/Services/Blogging Driver.php /Services_Blogging/Services/Blogging/Driver Blogger.php LiveJournal.php MetaWeblog.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-50960@lists.php.net to get a copy of this message | ||
cweiske Sun Feb 10 18:55:37 2008 UTC
Modified files:
/pear/Services_Blogging/Services/Blogging Driver.php
/pear/Services_Blogging/Services/Blogging/Driver Blogger.php
LiveJournal.php
MetaWeblog.php
Log:
Extend API to add support for drivers that allow different post types
(like normal text posts, images, videos, ...)
So till, sag was :)
http://cvs.php.net/viewvc.cgi/pear/Services_Blogging/Services/Blogging/Driver.php?r1=1.2&r2=1.3&diff_format=u Index: pear/Services_Blogging/Services/Blogging/Driver.php diff -u pear/Services_Blogging/Services/Blogging/Driver.php:1.2 pear/Services_Blogging/Services/Blogging/Driver.php:1.3 --- pear/Services_Blogging/Services/Blogging/Driver.php:1.2 Tue Jul 17 18:07:16 2007 +++ pear/Services_Blogging/Services/Blogging/Driver.php Sun Feb 10 18:55:37 2008 @@ -13,12 +13,16 @@ */ abstract class Services_Blogging_Driver { - /** * Error code: Username or password doesn't exist/are wrong */ const ERROR_USERIDPASS = 102; + /** + * Error code: Unsupported post type used in createPost() + */ + const ERROR_WRONGPOSTTYPE = 103; + /** @@ -44,15 +48,16 @@ - /** * Returns an array of strings thay define - * the properties that a post to this blog may - * have. + * the properties that a post to this blog may have. + * + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() * * @return array Array of strings */ - abstract public function getSupportedPostProperties(); + abstract public function getSupportedPostProperties($strPostType = 'post'); @@ -61,10 +66,14 @@ * for this driver. * * @param string $strProperty Property name/id to check + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() * * @return boolean If the property is supported */ - abstract public function isPostPropertySupported($strProperty); + abstract public function isPostPropertySupported( + $strProperty, $strPostType = 'post' + ); @@ -72,12 +81,52 @@ * Creates a new post object and returns that. * Automatically sets the driver object in the post. * + * Needs to be overwritten by drivers supporting multiple post types. + * + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() + * * @return Services_Blogging_Post New post object + * + * @throws Services_Blogging_Driver_Exception When an unsupported post + * type is used. */ - public function createNewPost() + public function createNewPost($strPostType = 'post') { + //this does not make much sense for drivers with only one + // post type, but it helps to keep apps consistent by + // validating parameters + $arSupportedTypes = $this->getSupportedPostTypes(); + if (!in_array($strPostType, $arSupportedTypes)) { + throw new Services_Blogging_Driver_Exception( + 'Unsupported post type "' . $strPostType . '"', + self::ERROR_WRONGPOSTTYPE + ); + } + + //when overwriting this method, create the different post instances + // here return new Services_Blogging_Post($this); - }//public function createNewPost() + }//public function createNewPost(..) + + + + /** + * Returns an array of supported post types. Pass one of them + * to createNewPost() to instantiate such a post object. + * + * Useful for drivers that support multiple post types like + * normal post ("post"), video and such. Most drivers support posts + * only. + * + * Needs to be overwritten by drivers supporting post types. + * + * @return array Array of strings (post types) + */ + public function getSupportedPostTypes() + { + return array('post'); + }//public function getSupportedPostTypes() }//abstract class Services_Blogging_Driver ?> \ No newline at end of file http://cvs.php.net/viewvc.cgi/pear/Services_Blogging/Services/Blogging/Driver/Blogger.php?r1=1.3&r2=1.4&diff_format=u Index: pear/Services_Blogging/Services/Blogging/Driver/Blogger.php diff -u pear/Services_Blogging/Services/Blogging/Driver/Blogger.php:1.3 pear/Services_Blogging/Services/Blogging/Driver/Blogger.php:1.4 --- pear/Services_Blogging/Services/Blogging/Driver/Blogger.php:1.3 Fri Feb 8 09:05:58 2008 +++ pear/Services_Blogging/Services/Blogging/Driver/Blogger.php Sun Feb 10 18:55:37 2008 @@ -183,12 +183,15 @@ * the properties that a post to this blog may * have. * + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() + * * @return array Array of strings */ - public function getSupportedPostProperties() + public function getSupportedPostProperties($strPostType = 'post') { return array(Services_Blogging_Post::CONTENT); - }//public function getSupportedPostProperties() + }//public function getSupportedPostProperties(..) @@ -197,13 +200,15 @@ * for this driver. * * @param string $strProperty Property name/id to check + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() * * @return boolean If the property is supported */ - public function isPostPropertySupported($strProperty) + public function isPostPropertySupported($strProperty, $strPostType = 'post') { return $strProperty == Services_Blogging_Post::CONTENT; - }//public function isPostPropertySupported($strProperty) + }//public function isPostPropertySupported(..) http://cvs.php.net/viewvc.cgi/pear/Services_Blogging/Services/Blogging/Driver/LiveJournal.php?r1=1.3&r2=1.4&diff_format=u Index: pear/Services_Blogging/Services/Blogging/Driver/LiveJournal.php diff -u pear/Services_Blogging/Services/Blogging/Driver/LiveJournal.php:1.3 pear/Services_Blogging/Services/Blogging/Driver/LiveJournal.php:1.4 --- pear/Services_Blogging/Services/Blogging/Driver/LiveJournal.php:1.3 Fri Feb 8 09:05:58 2008 +++ pear/Services_Blogging/Services/Blogging/Driver/LiveJournal.php Sun Feb 10 18:55:37 2008 @@ -239,7 +239,7 @@ /** - * The getPost method is intended to retrive a given post as an object of + * The getPost method is intended to retrieve a given post as an object of * the Services_Blogging_Post class; given the unique post id which is passed * as a parameter to the function. * @@ -386,12 +386,15 @@ * the properties that a post to this blog may * have. * + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() + * * @return array Array of strings */ - public function getSupportedPostProperties() + public function getSupportedPostProperties($strPostType = 'post') { return $this->arSupportedPostProperties; - }//public function getSupportedPostProperties() + }//public function getSupportedPostProperties(..) @@ -400,13 +403,15 @@ * for this driver. * * @param string $strProperty Property name/id to check + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() * * @return boolean If the property is supported */ - public function isPostPropertySupported($strProperty) + public function isPostPropertySupported($strProperty, $strPostType = 'post') { return in_array($strProperty, $this->arSupportedPostProperties); - }//public function isPostPropertySupported($strProperty) + }//public function isPostPropertySupported(..) http://cvs.php.net/viewvc.cgi/pear/Services_Blogging/Services/Blogging/Driver/MetaWeblog.php?r1=1.4&r2=1.5&diff_format=u Index: pear/Services_Blogging/Services/Blogging/Driver/MetaWeblog.php diff -u pear/Services_Blogging/Services/Blogging/Driver/MetaWeblog.php:1.4 pear/Services_Blogging/Services/Blogging/Driver/MetaWeblog.php:1.5 --- pear/Services_Blogging/Services/Blogging/Driver/MetaWeblog.php:1.4 Fri Feb 8 09:05:58 2008 +++ pear/Services_Blogging/Services/Blogging/Driver/MetaWeblog.php Sun Feb 10 18:55:37 2008 @@ -238,12 +238,15 @@ * the properties that a post to this blog may * have. * + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() + * * @return array Array of strings */ - public function getSupportedPostProperties() + public function getSupportedPostProperties($strPostType = 'post') { return $this->arSupportedPostProperties; - }//public function getSupportedPostProperties() + }//public function getSupportedPostProperties(..) @@ -252,13 +255,15 @@ * for this driver. * * @param string $strProperty Property name/id to check + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() * * @return boolean If the property is supported */ - public function isPostPropertySupported($strProperty) + public function isPostPropertySupported($strProperty, $strPostType = 'post') { return in_array($strProperty, $this->arSupportedPostProperties); - }//public function isPostPropertySupported($strProperty) + }//public function isPostPropertySupported(..)
http://cvs.php.net/viewvc.cgi/pear/Services_Blogging/Services/Blogging/Driver.php?r1=1.2&r2=1.3&diff_format=u Index: pear/Services_Blogging/Services/Blogging/Driver.php diff -u pear/Services_Blogging/Services/Blogging/Driver.php:1.2 pear/Services_Blogging/Services/Blogging/Driver.php:1.3 --- pear/Services_Blogging/Services/Blogging/Driver.php:1.2 Tue Jul 17 18:07:16 2007 +++ pear/Services_Blogging/Services/Blogging/Driver.php Sun Feb 10 18:55:37 2008 @@ -13,12 +13,16 @@ */ abstract class Services_Blogging_Driver { - /** * Error code: Username or password doesn't exist/are wrong */ const ERROR_USERIDPASS = 102; + /** + * Error code: Unsupported post type used in createPost() + */ + const ERROR_WRONGPOSTTYPE = 103; + /** @@ -44,15 +48,16 @@ - /** * Returns an array of strings thay define - * the properties that a post to this blog may - * have. + * the properties that a post to this blog may have. + * + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() * * @return array Array of strings */ - abstract public function getSupportedPostProperties(); + abstract public function getSupportedPostProperties($strPostType = 'post'); @@ -61,10 +66,14 @@ * for this driver. * * @param string $strProperty Property name/id to check + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() * * @return boolean If the property is supported */ - abstract public function isPostPropertySupported($strProperty); + abstract public function isPostPropertySupported( + $strProperty, $strPostType = 'post' + ); @@ -72,12 +81,52 @@ * Creates a new post object and returns that. * Automatically sets the driver object in the post. * + * Needs to be overwritten by drivers supporting multiple post types. + * + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() + * * @return Services_Blogging_Post New post object + * + * @throws Services_Blogging_Driver_Exception When an unsupported post + * type is used. */ - public function createNewPost() + public function createNewPost($strPostType = 'post') { + //this does not make much sense for drivers with only one + // post type, but it helps to keep apps consistent by + // validating parameters + $arSupportedTypes = $this->getSupportedPostTypes(); + if (!in_array($strPostType, $arSupportedTypes)) { + throw new Services_Blogging_Driver_Exception( + 'Unsupported post type "' . $strPostType . '"', + self::ERROR_WRONGPOSTTYPE + ); + } + + //when overwriting this method, create the different post instances + // here return new Services_Blogging_Post($this); - }//public function createNewPost() + }//public function createNewPost(..) + + + + /** + * Returns an array of supported post types. Pass one of them + * to createNewPost() to instantiate such a post object. + * + * Useful for drivers that support multiple post types like + * normal post ("post"), video and such. Most drivers support posts + * only. + * + * Needs to be overwritten by drivers supporting post types. + * + * @return array Array of strings (post types) + */ + public function getSupportedPostTypes() + { + return array('post'); + }//public function getSupportedPostTypes() }//abstract class Services_Blogging_Driver ?> \ No newline at end of file http://cvs.php.net/viewvc.cgi/pear/Services_Blogging/Services/Blogging/Driver/Blogger.php?r1=1.3&r2=1.4&diff_format=u Index: pear/Services_Blogging/Services/Blogging/Driver/Blogger.php diff -u pear/Services_Blogging/Services/Blogging/Driver/Blogger.php:1.3 pear/Services_Blogging/Services/Blogging/Driver/Blogger.php:1.4 --- pear/Services_Blogging/Services/Blogging/Driver/Blogger.php:1.3 Fri Feb 8 09:05:58 2008 +++ pear/Services_Blogging/Services/Blogging/Driver/Blogger.php Sun Feb 10 18:55:37 2008 @@ -183,12 +183,15 @@ * the properties that a post to this blog may * have. * + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() + * * @return array Array of strings */ - public function getSupportedPostProperties() + public function getSupportedPostProperties($strPostType = 'post') { return array(Services_Blogging_Post::CONTENT); - }//public function getSupportedPostProperties() + }//public function getSupportedPostProperties(..) @@ -197,13 +200,15 @@ * for this driver. * * @param string $strProperty Property name/id to check + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() * * @return boolean If the property is supported */ - public function isPostPropertySupported($strProperty) + public function isPostPropertySupported($strProperty, $strPostType = 'post') { return $strProperty == Services_Blogging_Post::CONTENT; - }//public function isPostPropertySupported($strProperty) + }//public function isPostPropertySupported(..) http://cvs.php.net/viewvc.cgi/pear/Services_Blogging/Services/Blogging/Driver/LiveJournal.php?r1=1.3&r2=1.4&diff_format=u Index: pear/Services_Blogging/Services/Blogging/Driver/LiveJournal.php diff -u pear/Services_Blogging/Services/Blogging/Driver/LiveJournal.php:1.3 pear/Services_Blogging/Services/Blogging/Driver/LiveJournal.php:1.4 --- pear/Services_Blogging/Services/Blogging/Driver/LiveJournal.php:1.3 Fri Feb 8 09:05:58 2008 +++ pear/Services_Blogging/Services/Blogging/Driver/LiveJournal.php Sun Feb 10 18:55:37 2008 @@ -239,7 +239,7 @@ /** - * The getPost method is intended to retrive a given post as an object of + * The getPost method is intended to retrieve a given post as an object of * the Services_Blogging_Post class; given the unique post id which is passed * as a parameter to the function. * @@ -386,12 +386,15 @@ * the properties that a post to this blog may * have. * + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() + * * @return array Array of strings */ - public function getSupportedPostProperties() + public function getSupportedPostProperties($strPostType = 'post') { return $this->arSupportedPostProperties; - }//public function getSupportedPostProperties() + }//public function getSupportedPostProperties(..) @@ -400,13 +403,15 @@ * for this driver. * * @param string $strProperty Property name/id to check + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() * * @return boolean If the property is supported */ - public function isPostPropertySupported($strProperty) + public function isPostPropertySupported($strProperty, $strPostType = 'post') { return in_array($strProperty, $this->arSupportedPostProperties); - }//public function isPostPropertySupported($strProperty) + }//public function isPostPropertySupported(..) http://cvs.php.net/viewvc.cgi/pear/Services_Blogging/Services/Blogging/Driver/MetaWeblog.php?r1=1.4&r2=1.5&diff_format=u Index: pear/Services_Blogging/Services/Blogging/Driver/MetaWeblog.php diff -u pear/Services_Blogging/Services/Blogging/Driver/MetaWeblog.php:1.4 pear/Services_Blogging/Services/Blogging/Driver/MetaWeblog.php:1.5 --- pear/Services_Blogging/Services/Blogging/Driver/MetaWeblog.php:1.4 Fri Feb 8 09:05:58 2008 +++ pear/Services_Blogging/Services/Blogging/Driver/MetaWeblog.php Sun Feb 10 18:55:37 2008 @@ -238,12 +238,15 @@ * the properties that a post to this blog may * have. * + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() + * * @return array Array of strings */ - public function getSupportedPostProperties() + public function getSupportedPostProperties($strPostType = 'post') { return $this->arSupportedPostProperties; - }//public function getSupportedPostProperties() + }//public function getSupportedPostProperties(..) @@ -252,13 +255,15 @@ * for this driver. * * @param string $strProperty Property name/id to check + * @param string $strPostType Type of post to create. + * @see getSupportedPostTypes() * * @return boolean If the property is supported */ - public function isPostPropertySupported($strProperty) + public function isPostPropertySupported($strProperty, $strPostType = 'post') { return in_array($strProperty, $this->arSupportedPostProperties); - }//public function isPostPropertySupported($strProperty) + }//public function isPostPropertySupported(..)