[pLog-svn] r816 - in plugins/trunk: . flickr flickr/class
flickr/class/action flickr/class/xml flickr/install
flickr/locale flickr/templates
mark at devel.plogworld.net
mark at devel.plogworld.net
Mon Jan 24 10:18:46 GMT 2005
Author: mark
Date: 2005-01-24 10:18:46 +0000 (Mon, 24 Jan 2005)
New Revision: 816
Added:
plugins/trunk/flickr/
plugins/trunk/flickr/class/
plugins/trunk/flickr/class/action/
plugins/trunk/flickr/class/action/pluginflickrconfigaction.class.php
plugins/trunk/flickr/class/action/pluginflickrupdateconfigaction.class.php
plugins/trunk/flickr/class/xml/
plugins/trunk/flickr/class/xml/XMLParser.class.php
plugins/trunk/flickr/install/
plugins/trunk/flickr/install/flickr.template
plugins/trunk/flickr/locale/
plugins/trunk/flickr/locale/locale_en_UK.php
plugins/trunk/flickr/locale/locale_zh_TW.php
plugins/trunk/flickr/pluginflickr.class.php
plugins/trunk/flickr/readme.txt
plugins/trunk/flickr/templates/
plugins/trunk/flickr/templates/flickr.template
Log:
Added: plugins/trunk/flickr/class/action/pluginflickrconfigaction.class.php
===================================================================
--- plugins/trunk/flickr/class/action/pluginflickrconfigaction.class.php 2005-01-24 08:57:44 UTC (rev 815)
+++ plugins/trunk/flickr/class/action/pluginflickrconfigaction.class.php 2005-01-24 10:18:46 UTC (rev 816)
@@ -0,0 +1,53 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+
+ /**
+ * shows a form with the current configuration
+ */
+ class PluginFlickrConfigAction extends AdminAction
+ {
+
+ function PluginFlickrConfigAction( $actionInfo, $request )
+ {
+ $this->AdminAction( $actionInfo, $request );
+ }
+
+ function perform()
+ {
+ // load some configuration settings
+ $blogSettings = $this->_blogInfo->getSettings();
+ $pluginEnabled = $blogSettings->getValue( "plugin_flickr_enabled" );
+ $email = $blogSettings->getValue( "plugin_flickr_email" );
+ $password = $blogSettings->getValue( "plugin_flickr_password" );
+ $aliasName = $blogSettings->getValue( "plugin_flickr_aliasname" );
+ $albumThumbnailSize = $blogSettings->getValue( "plugin_flickr_albumthumbnailsize" );
+ if ( $albumThumbnailSize == "" ) $albumThumbnailSize = "s";
+ $photoThumbnailSize = $blogSettings->getValue( "plugin_flickr_photothumbnailsize" );
+ if ( $photoThumbnailSize == "" ) $photoThumbnailSize = "s";
+ $showPrivate = $blogSettings->getValue( "plugin_flickr_showprivate" );
+ if ( $showPrivate == "") $showPrivate = 1;
+ $showNote = $blogSettings->getValue( "plugin_flickr_shownote" );
+ if ( $showNote == "") $showNote = 1;
+ $expiredTime = $blogSettings->getValue( "plugin_flickr_expiredtime" );
+ if ( $expiredTime == "") $expiredTime = 3600;
+
+ // create a view and export the settings to the template
+ $this->_view = new AdminPluginTemplatedView( $this->_blogInfo, "flickr", "flickr", true );
+ $this->_view->setValue( "pluginEnabled", $pluginEnabled );
+ $this->_view->setValue( "email", $email );
+ $this->_view->setValue( "password", $password );
+ $this->_view->setValue( "aliasName", $aliasName );
+ $this->_view->setValue( "albumThumbnailSize", $albumThumbnailSize );
+ $this->_view->setValue( "photoThumbnailSize", $photoThumbnailSize );
+ $this->_view->setValue( "showPrivate", $showPrivate );
+ $this->_view->setValue( "showNote", $showNote );
+ $this->_view->setValue( "expiredTime", $expiredTime );
+
+ $this->setCommonData();
+
+ return true;
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/flickr/class/action/pluginflickrupdateconfigaction.class.php
===================================================================
--- plugins/trunk/flickr/class/action/pluginflickrupdateconfigaction.class.php 2005-01-24 08:57:44 UTC (rev 815)
+++ plugins/trunk/flickr/class/action/pluginflickrupdateconfigaction.class.php 2005-01-24 10:18:46 UTC (rev 816)
@@ -0,0 +1,108 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminerrorview.class.php" );
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminmessageview.class.php" );
+
+ /**
+ * updates the plugin configuration
+ */
+ class PluginFlickrUpdateConfigAction extends AdminAction
+ {
+ var $_pluginEnabled;
+ var $_email;
+ var $_password;
+ var $_aliasName;
+ var $_albumThumbnailSize;
+ var $_photoThumbnailSize;
+ var $_showPrivate;
+ var $_showNote;
+ var $_expiredTime;
+
+ function PluginFlickrUpdateConfigAction( $actionInfo, $request )
+ {
+ $this->AdminAction( $actionInfo, $request );
+ }
+
+ function validate()
+ {
+ $this->_pluginEnabled = $this->_request->getValue( "pluginEnabled" );
+ $this->_pluginEnabled = ($this->_pluginEnabled != "" );
+
+ $this->_email = $this->_request->getValue( "email" );
+ if( $this->_email == "" ) {
+ $this->_view = new AdminErrorView( $this->_blogInfo );
+ $this->_view->setValue( "message", $this->_locale->tr("flickr_error_email"));
+ $this->setCommonData();
+ return false;
+ }
+
+ $this->_password = $this->_request->getValue( "password" );
+ if( $this->_password == "" ) {
+ $this->_view = new AdminErrorView( $this->_blogInfo );
+ $this->_view->setValue( "message", $this->_locale->tr("flickr_error_password"));
+ $this->setCommonData();
+ return false;
+ }
+
+ $this->_aliasName = $this->_request->getValue( "aliasName" );
+ if( $this->_aliasName == "" ) {
+ $this->_view = new AdminErrorView( $this->_blogInfo );
+ $this->_view->setValue( "message", $this->_locale->tr("flickr_error_aliasname"));
+ $this->setCommonData();
+ return false;
+ }
+
+ $this->_albumThumbnailSize = $this->_request->getValue( "albumThumbnailSize" );
+ $this->_photoThumbnailSize = $this->_request->getValue( "photoThumbnailSize" );
+ $this->_showPrivate = $this->_request->getValue( "showPrivate" );
+ $this->_showNote = $this->_request->getValue( "showNote" );
+
+ $this->_expiredTime = $this->_request->getValue( "expiredTime" );
+ if( $this->_expiredTime < 3600 ) {
+ $this->_view = new AdminErrorView( $this->_blogInfo );
+ $this->_view->setValue( "message", $this->_locale->tr("flickr_error_expiredtime"));
+ $this->setCommonData();
+ return false;
+ }
+ return true;
+ }
+
+ function perform()
+ {
+ // update the plugin configurations to blog setting
+ $blogSettings = $this->_blogInfo->getSettings();
+ $blogSettings->setValue( "plugin_flickr_enabled", $this->_pluginEnabled );
+ $blogSettings->setValue( "plugin_flickr_email", $this->_email );
+ $blogSettings->setValue( "plugin_flickr_password", $this->_password );
+ $blogSettings->setValue( "plugin_flickr_aliasname", $this->_aliasName );
+ $blogSettings->setValue( "plugin_flickr_albumthumbnailsize", $this->_albumThumbnailSize );
+ $blogSettings->setValue( "plugin_flickr_photothumbnailsize", $this->_photoThumbnailSize );
+ $blogSettings->setValue( "plugin_flickr_showprivate", $this->_showPrivate );
+ $blogSettings->setValue( "plugin_flickr_shownote", $this->_showNote );
+ $blogSettings->setValue( "plugin_flickr_expiredtime", $this->_expiredTime );
+ $this->_blogInfo->setSettings( $blogSettings );
+
+ // save the blogs settings
+ $blogs = new Blogs();
+ if( !$blogs->updateBlog( $this->_blogInfo->getId(), $this->_blogInfo )) {
+ $this->_view = new AdminErrorView( $this->_blogInfo );
+ $this->_view->setValue( "message", $this->_locale->tr("error_updating_settings"));
+ $this->setCommonData();
+
+ return false;
+ }
+
+ // if everything went ok...
+ $this->_blogInfo->setSettings( $blogSettings );
+ $this->_session->setValue( "blogInfo", $this->_blogInfo );
+ $this->saveSession();
+
+ $this->_view = new AdminMessageView( $this->_blogInfo );
+ $this->_view->setMessage( $this->_locale->tr("flickr_settings_saved_ok"));
+ $this->setCommonData();
+
+ return true;
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/flickr/class/xml/XMLParser.class.php
===================================================================
--- plugins/trunk/flickr/class/xml/XMLParser.class.php 2005-01-24 08:57:44 UTC (rev 815)
+++ plugins/trunk/flickr/class/xml/XMLParser.class.php 2005-01-24 10:18:46 UTC (rev 816)
@@ -0,0 +1,116 @@
+<?php
+
+//
+// Based on code found online at:
+// http://php.net/manual/en/function.xml-parse-into-struct.php
+//
+// Author: Eric Pollmann
+// Released into public domain September 2003
+// http://eric.pollmann.net/work/public_domain/
+//
+
+class XMLParser {
+ var $data; // Input XML data buffer
+ var $vals; // Struct created by xml_parse_into_struct
+ var $collapse_dups; // If there is only one tag of a given name,
+ // shall we store as scalar or array?
+ var $index_numeric; // Index tags by numeric position, not name.
+ // useful for ordered XML like CallXML.
+
+ // Read in XML on object creation.
+ // We can take raw XML data, a stream, a filename, or a url.
+ function XMLParser($data_source, $data_source_type='raw', $collapse_dups=0, $index_numeric=0) {
+ $this->collapse_dups = $collapse_dups;
+ $this->index_numeric = $index_numeric;
+ $this->data = '';
+ if ($data_source_type == 'raw')
+ $this->data = $data_source;
+
+ elseif ($data_source_type == 'stream') {
+ while (!feof($data_source))
+ $this->data .= fread($data_source, 1000);
+
+ // try filename, then if that fails...
+ } elseif (file_exists($data_source))
+ $this->data = implode('', file($data_source));
+
+ // try url
+ else {
+ $fp = fopen($data_source,'r');
+ while (!feof($fp))
+ $this->data .= fread($fp, 1000);
+ fclose($fp);
+ }
+ }
+
+ // Parse the XML file into a verbose, flat array struct.
+ // Then, coerce that into a simple nested array.
+ function getTree() {
+ $parser = xml_parser_create('ISO-8859-1');
+ xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
+ xml_parse_into_struct($parser, $this->data, $vals, $index);
+ xml_parser_free($parser);
+
+ $i = -1;
+ return $this->getchildren($vals, $i);
+ }
+
+ // internal function: build a node of the tree
+ function buildtag($thisvals, $vals, &$i, $type) {
+
+ if (isset($thisvals['attributes']))
+ $tag['ATTRIBUTES'] = $thisvals['attributes'];
+
+ // complete tag, just return it for storage in array
+ if ($type === 'complete')
+ $tag['VALUE'] = $thisvals['value'];
+
+ // open tag, recurse
+ else
+ $tag = array_merge($tag, $this->getchildren($vals, $i));
+
+ return $tag;
+ }
+
+ // internal function: build an nested array representing children
+ function getchildren($vals, &$i) {
+ $children = array(); // Contains node data
+
+ // Node has CDATA before it's children
+ if ($i > -1 && isset($vals[$i]['value']))
+ $children['VALUE'] = $vals[$i]['value'];
+
+ // Loop through children, until hit close tag or run out of tags
+ while (++$i < count($vals)) {
+
+ $type = $vals[$i]['type'];
+
+ // 'cdata': Node has CDATA after one of it's children
+ // (Add to cdata found before in this case)
+ if ($type === 'cdata')
+ $children['VALUE'] .= $vals[$i]['value'];
+
+ // 'complete': At end of current branch
+ // 'open': Node has children, recurse
+ elseif ($type === 'complete' || $type === 'open') {
+ $tag = $this->buildtag($vals[$i], $vals, $i, $type);
+ if ($this->index_numeric) {
+ $tag['TAG'] = $vals[$i]['tag'];
+ $children[] = $tag;
+ } else
+ $children[$vals[$i]['tag']][] = $tag;
+ }
+
+ // 'close: End of node, return collected data
+ // Do not increment $i or nodes disappear!
+ elseif ($type === 'close')
+ break;
+ }
+ if ($this->collapse_dups)
+ foreach($children as $key => $value)
+ if (is_array($value) && (count($value) == 1))
+ $children[$key] = $value[0];
+ return $children;
+ }
+}
+?>
Added: plugins/trunk/flickr/install/flickr.template
===================================================================
--- plugins/trunk/flickr/install/flickr.template 2005-01-24 08:57:44 UTC (rev 815)
+++ plugins/trunk/flickr/install/flickr.template 2005-01-24 10:18:46 UTC (rev 816)
@@ -0,0 +1,35 @@
+{include file="$blogtemplate/header.template"}
+{assign var=albumId value=$smarty.request.album}
+{assign var=photoId value=$smarty.request.photo}
+{assign var=secretId value=$smarty.request.secret}
+{if $albumId != NULL && $photoId != NULL && secretId != NULL}
+ {assign var=flickrPhotoInfo value=$flickr->getPhotoInfo($photoId,$secretId)}
+ <h3>{$flickrPhotoInfo.title}</h3>
+ <span class="date">{$flickrPhotoInfo.description} | {$flickrPhotoInfo.date}</span><br /><br />
+ <a href="{$flickrPhotoInfo.originalimageUrl}"><img class="annotated" src="{$flickrPhotoInfo.resizeimageUrl}" alt="" usemap="imgmap" /></a><br />
+ {assign var=flickrNotes value=$flickrPhotoInfo.notes}
+ <map id="imgmap">
+ {foreach item=flickrNote from=$flickrNotes}
+ <area alt="" title="{$flickrNote.noteDesc}" nohref="nohref" shape="rect" coords="{$flickrNote.noteX},{$flickrNote.noteY},{$flickrNote.noteX+$flickrNote.noteW-1},{$flickrNote.noteY+$flickrNote.noteH-1}" />
+ {/foreach}
+ </map>
+ {assign var=flickrTags value=$flickrPhotoInfo.tags}
+ See Similar: {foreach item=flickrTag from=$flickrTags}<a href="{$flickrTag.tagUrl}">{$flickrTag.tagName}</a> {/foreach}<br />
+ Flickr URL: <a href="{$flickrPhotoInfo.flickrUrl}">See the photo in Flickr ({$flickrPhotoInfo.comments} Comments)</a><br />
+{elseif $albumId != NULL && ($photoId == NULL || secretId == NULL)}
+ {assign var=flickrPhotos value=$flickr->getPhotos($albumId)}
+ {foreach item=flickrPhoto from=$flickrPhotos}
+ <a href="{$flickrPhoto.photoUrl}"><img src="{$flickrPhoto.thumbnailUrl}" alt="" /></a>
+ {/foreach}
+{else}
+ {assign var=flickrAlbums value=$flickr->getPhotoList()}
+ {foreach name=flickrAlbum item=flickrAlbum from=$flickrAlbums}
+ <a href="{$flickrAlbum.albumUrl}"><img src="{$flickrAlbum.thumbnailUrl}" alt="{$flickrAlbum.title}" /></a><br />
+ Title: {$flickrAlbum.title} <br />
+ Description: {$flickrAlbum.description} <br />
+ Photos: <a href="{$flickrAlbum.albumUrl}">{$flickrAlbum.photos}</a> <br />
+ Flickr URL: <a href="{$flickrAlbum.flickrUrl}">See the album in Flickr</a> <br /><br />
+ {/foreach}
+ {assign var=totalAlbums value=$smarty.foreach.flickrAlbum.total}
+{/if}
+{include file="$blogtemplate/footer.template"}
\ No newline at end of file
Added: plugins/trunk/flickr/locale/locale_en_UK.php
===================================================================
--- plugins/trunk/flickr/locale/locale_en_UK.php 2005-01-24 08:57:44 UTC (rev 815)
+++ plugins/trunk/flickr/locale/locale_en_UK.php 2005-01-24 10:18:46 UTC (rev 816)
@@ -0,0 +1,20 @@
+<?php
+$messages["flickr_email"] = "E-Mail";
+$messages["flickr_password"] = "Password";
+$messages["flickr_aliasname"] = "Alias Name";
+$messages["flickr_albumthumbnailsize"] = "Album Thumbnail Size";
+$messages["flickr_photothumbnailsize"] = "Photo Thumbnail Size";
+$messages["flickr_showprivate"] = "Show Private Photos";
+$messages["flickr_shownote"] = "Show Notes";
+$messages["flickr_expiredtime"] = "Cache Expired Time";
+$messages["flickr_yes"] = "Yes";
+$messages["flickr_no"] = "No";
+$messages["flickr_plugin_configuration"] = "Configuration this plugin";
+$messages["flickr_plugin_enabled"] = "Enable this plugin";
+$messages["flickr_plugin"] = "Flickr Integration Plugin";
+$messages["flickr_settings_saved_ok"] = "Flickr settings saved successfully!";
+$messages["flickr_error_email"] = "E-Mail can not be empty!";
+$messages["flickr_error_password"] = "Password can not be empty!";
+$messages["flickr_error_aliasname"] = "Alias Name can not be empty";
+$messages["flickr_error_expiredtime"] = "To reduce the loading of Flickr server, the expired time can not shorter then 3600 secs.";
+?>
\ No newline at end of file
Added: plugins/trunk/flickr/locale/locale_zh_TW.php
===================================================================
--- plugins/trunk/flickr/locale/locale_zh_TW.php 2005-01-24 08:57:44 UTC (rev 815)
+++ plugins/trunk/flickr/locale/locale_zh_TW.php 2005-01-24 10:18:46 UTC (rev 816)
@@ -0,0 +1,20 @@
+<?php
+$messages["flickr_email"] = "帳è";
+$messages["flickr_password"] = "å¯ç¢¼";
+$messages["flickr_aliasname"] = "代å";
+$messages["flickr_albumthumbnailsize"] = "ç¸ç°¿ç¸®å大å°";
+$messages["flickr_photothumbnailsize"] = "ç¸ç縮å大å°";
+$messages["flickr_showprivate"] = "顯示é±èç¸ç";
+$messages["flickr_shownote"] = "顯示ç¸ç註è¨";
+$messages["flickr_expiredtime"] = "æ«åæªæææé";
+$messages["flickr_yes"] = "æ¯";
+$messages["flickr_no"] = "å¦";
+$messages["flickr_plugin_configuration"] = "夿ç¨å¼è¨å®";
+$messages["flickr_plugin_enabled"] = "åå夿ç¨å¼";
+$messages["flickr_plugin"] = "Flickr æ´å夿ç¨å¼";
+$messages["flickr_settings_saved_ok"] = "Flickr è¨å®å²åæåã";
+$messages["flickr_error_email"] = "帳èé¯èª¤ï¼ä¸å¯çºç©ºç½ã";
+$messages["flickr_error_password"] = "å¯ç¢¼é¯èª¤ï¼ä¸å¯çºç©ºç½ã";
+$messages["flickr_error_aliasname"] = "代åé¯èª¤ï¼ä¸å¯çºç©ºç½ã";
+$messages["flickr_error_expiredtime"] = "çºé²æ¢ Flickr 伺æå¨è² è·ééãæççæ«åæªæææçº 3600 ç§ã";
+?>
\ No newline at end of file
Added: plugins/trunk/flickr/pluginflickr.class.php
===================================================================
--- plugins/trunk/flickr/pluginflickr.class.php 2005-01-24 08:57:44 UTC (rev 815)
+++ plugins/trunk/flickr/pluginflickr.class.php 2005-01-24 10:18:46 UTC (rev 816)
@@ -0,0 +1,300 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+ include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
+ include_once( PLOG_CLASS_PATH."class/net/requestgenerator.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/flickr/class/xml/XMLParser.class.php" );
+
+ //Used as the root for building the img URLs
+ define ('FLICKR_PHOTO_ROOT', 'http://www.flickr.com/photos/');
+
+ //Used as the root for Flickr API service URLs
+ define ('FLICKR_GET_PHOTOLIST', 'http://www.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=');
+ define ('FLICKR_GET_PHOTOS', 'http://www.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=');
+ define ('FLICKR_GET_PHOTOINFO', 'http://www.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=');
+
+ //DO NOT CHANGE OR STEAL THIS
+ //This is the API key that was assigned to this plog plugin by Flickr.
+ //If you need an API key for your own project
+ //goto http://flickr.com/services/api/misc.api_keys.html
+ define ('FLICKR_API_KEY', '642d5965f8ecba92fb78ff5d83993a02');
+
+ /**
+ * Plugin that offers features to integrate the Flickr Photo Gallery Service
+ */
+ class PluginFlickr extends PluginBase
+ {
+ var $cacheFolder; //pLog Temp Folder
+ var $email; //Your Flickr account logon (email address you registered with)
+ var $password; //Your Flickr account password
+ var $aliasName; //Your Flickr alias name
+ var $albumThumbnailSize; //Size of the thumbnail you want to appear in the album thumbnail page
+ var $photoThumbnailSize; //Size of the thumbnail you want to appear in the album thumbnail page
+ var $showPrivate; //Whether or not to show your "private" Flickr photos
+ var $showNote; //Whether or not to show your "notes" of photo
+ var $expiredTime; //Duration for cache expired
+ var $userRoot; //Root for links in the output
+
+ function PluginFlickr()
+ {
+ $this->PluginBase();
+
+ $this->id = "flickr";
+ $this->author = "Mark Wu";
+ $this->desc = '<p>The pLog Flickr plugin is inspired by <a href="http://www.worrad.com/archives/2004/11/23/flickr-gallery-wp-plugin/">Flickr Gallery Plugin</a> written by Ray. </p><ol><li>Unzip the zip files into temp folder </li><li>Upload <strong>/class/*.*</strong> to <strong>/your-blog/class</strong> </li><li>Upload <strong>/js/*.*</strong> to <strong>/your-blog/js</strong> </li><li>Upload <strong>/plugins/*.*</strong> to <strong>/your-blog/plugins</strong> </li><li>Upload <strong>/templates/*.*</strong> to <strong>/your-blog/templates/grey</strong> (I assume you use grey template) </li><li>Add the follow CSS code to /styles/grey.css (I assume you use grey template)</li></ol><blockquote><p><strong>a.annotation {<br /> position: absolute;<br /> border: 1px solid white;<br /> padding: 0;<br /> display: none;<br />}<br />a.annotation span {<br /> display: block;<br /> width: 100%;<br /> height: 100%;<br /> /* Setup opaque background in notes box with browser specific opacity<br /> * properties (they are not valid CSS - sorry). If having valid CSS is<br /> * so important to you just get rid of the next 4 lines after these<br /> * comments (you will sacrifice the opaque background in the notes<br /> * boxes though).<br /> */<br /> background: white;<br /> opacity: 0.2;<br /> -moz-opacity: 0.2;<br /> filter: alpha(opacity=20);<br />}</strong></p><p><strong>a.annotation:hover {<br /> border-color: yellow;<br />}</strong></p></blockquote><ol start="7"><li>Add the following template code to your header.template</li></ol><blockquote><p><strong><script type="text/javascript" src="js/annimg/annimg.js"></script></strong> </p></blockquote><ol start="8"><li>Configure the Flickr Parameters through the configuration panel <ul><li>Your Flickr Account </li><li>Your Flickr Password </li><li>Alias Name </li><li>Thumbnail Size of Album </li><li>Thumbnail Size of Photo </li><li>Show Private Photos </li><li>Show Notes</li><li>Cache Expire (Secs)</li></ul></li></ol>';
+
+ $config =& Config::getConfig();
+ $this->cacheFolder = $config->getValue('temp_folder');
+
+ $this->locales = Array( "en_UK" , "zh_TW" );
+
+ $this->init();
+ }
+
+ function init()
+ {
+ $this->registerAdminAction( "flickr", "PluginFlickrConfigAction" );
+ $this->registerAdminAction( "updateFlickrConfig", "PluginFlickrUpdateConfigAction" );
+
+ $menu =& Menu::getMenu();
+ if( !$menu->entryExists( "/menu/controlCenter/manageIntegrationPlugins" ))
+ $this->addMenuEntry( "/menu/controlCenter", "manageIntegrationPlugins", "", "", true, false );
+ $this->addMenuEntry( "/menu/controlCenter/manageIntegrationPlugins", "Flickr", "?op=flickr", "" );
+ }
+
+ function register()
+ {
+ $this->cacheFolder = $this->cacheFolder.'/'.$this->blogInfo->getId();
+ if( !File::exists( $this->cacheFolder )) {
+ $this->log->debug( "creating temporary folder".$this->tempFolder );
+ File::createDir( $this->cacheFolder );
+ }
+
+ $blogSettings = $this->blogInfo->getSettings();
+ $this->pluginEnabled = $blogSettings->getValue( "plugin_flickr_enabled" );
+ $this->email = $blogSettings->getValue( "plugin_flickr_email" );
+ $this->password = $blogSettings->getValue( "plugin_flickr_password" );
+ $this->aliasName = $blogSettings->getValue( "plugin_flickr_aliasname" );
+ $this->albumThumbnailSize = $blogSettings->getValue( "plugin_flickr_albumthumbnailsize" );
+ $this->photoThumbnailSize = $blogSettings->getValue( "plugin_flickr_photothumbnailsize" );
+ $this->showPrivate = $blogSettings->getValue( "plugin_flickr_showprivate" );
+ $this->showNote = $blogSettings->getValue( "plugin_flickr_shownote" );
+ $this->expiredTime = $blogSettings->getValue( "plugin_flickr_expiredtime" );
+ }
+
+ /**
+ * Get the photo albums from specific user
+ */
+ function getPhotoList()
+ {
+ $apiUrl = FLICKR_GET_PHOTOLIST.FLICKR_API_KEY;
+ $apiUrl .= '&email=' . $this->email . '&password=' . $this->password;
+
+ $rg = new RawRequestGenerator($this->blogInfo);
+ $this->userRoot = $rg->templatePage( "flickr" );
+
+ $data = $this->cached_get_file_contents($apiUrl, 'r', $this->expiredTime, $this->cacheFolder);
+ $parser = new XMLParser($data, 'raw', 1);
+ $tree = $parser->getTree();
+
+ $total_albums = count($tree['RSP']['PHOTOSETS']['PHOTOSET']);
+ $albums = Array();
+
+ if ($tree['RSP']['PHOTOSETS']['PHOTOSET'][0] != NULL) {
+ for ($i = 0; $i < $total_albums; $i++) {
+ $album = Array();
+
+ $albumId = $tree['RSP']['PHOTOSETS']['PHOTOSET'][$i]['ATTRIBUTES']['ID'];
+ $albumPrimary = $tree['RSP']['PHOTOSETS']['PHOTOSET'][$i]['ATTRIBUTES']['PRIMARY'];
+ $albumSecret =$tree['RSP']['PHOTOSETS']['PHOTOSET'][$i]['ATTRIBUTES']['SECRET'];
+
+ $album['title'] = $tree['RSP']['PHOTOSETS']['PHOTOSET'][$i]['TITLE']['VALUE'];
+ $album['description'] = $tree['RSP']['PHOTOSETS']['PHOTOSET'][$i]['DESCRIPTION']['VALUE'];
+ $album['photos'] =$tree['RSP']['PHOTOSETS']['PHOTOSET'][$i]['ATTRIBUTES']['PHOTOS'];
+ $album['thumbnailUrl'] = FLICKR_PHOTO_ROOT.$albumPrimary."_".$albumSecret."_".$this->albumThumbnailSize.".jpg";
+ $album['flickrUrl'] = FLICKR_PHOTO_ROOT.$this->aliasName."/sets/".$albumId;
+ $album['albumUrl'] = $this->userRoot."&album=".$albumId;
+
+ array_push( $albums, $album);
+ }
+ } else {
+ $album = Array();
+
+ $albumId = $tree['RSP']['PHOTOSETS']['PHOTOSET']['ATTRIBUTES']['ID'];
+ $albumPrimary = $tree['RSP']['PHOTOSETS']['PHOTOSET']['ATTRIBUTES']['PRIMARY'];
+ $albumSecret =$tree['RSP']['PHOTOSETS']['PHOTOSET']['ATTRIBUTES']['SECRET'];
+
+ $album['title'] = $tree['RSP']['PHOTOSETS']['PHOTOSET']['TITLE']['VALUE'];
+ $album['description'] = $tree['RSP']['PHOTOSETS']['PHOTOSET']['DESCRIPTION']['VALUE'];
+ $album['photos'] =$tree['RSP']['PHOTOSETS']['PHOTOSET']['ATTRIBUTES']['PHOTOS'];
+ $album['thumbnailUrl'] = FLICKR_PHOTO_ROOT.$albumPrimary."_".$albumSecret."_".$this->albumThumbnailSize.".jpg";
+ $album['flickrUrl'] = FLICKR_PHOTO_ROOT.$this->aliasName."/sets/".$albumId;
+ $album['albumUrl'] = $this->userRoot."&album=".$albumId;
+
+ array_push( $albums, $album);
+ }
+ return $albums;
+ }
+
+ /**
+ * Get the photos from specific photo album
+ */
+ function getPhotos($albumId)
+ {
+ $apiUrl = FLICKR_GET_PHOTOS.FLICKR_API_KEY;
+ if ($this->showPrivate == 1)
+ $apiUrl .= '&photoset_id=' . $albumId;
+ else
+ $apiUrl .= '&email=' . $this->email . '&password=' . $this->password . '&photoset_id=' . $albumId;
+
+ $data = $this->cached_get_file_contents($apiUrl, 'r', $this->expiredTime, $this->cacheFolder);
+ $parser = new XMLParser($data, 'raw', 1);
+ $tree = $parser->getTree();
+
+ $rg = new RawRequestGenerator($this->blogInfo);
+ $this->userRoot = $rg->templatePage( "flickr" );
+
+ $totalPhotos = count($tree['RSP']['PHOTOSET']['PHOTO']);
+ $photos = Array();
+
+ if ($tree['RSP']['PHOTOSET']['PHOTO'][0] != NULL) {
+ for ($i = 0; $i < $totalPhotos; $i++) {
+ $photo = Array();
+
+ $photoId = $tree['RSP']['PHOTOSET']['PHOTO'][$i]['ATTRIBUTES']['ID'];
+ $photoSecret =$tree['RSP']['PHOTOSET']['PHOTO'][$i]['ATTRIBUTES']['SECRET'];
+
+ $photo['thumbnailUrl'] = FLICKR_PHOTO_ROOT.$photoId."_".$photoSecret."_".$this->photoThumbnailSize.".jpg";
+ $photo['flickrUrl'] = FLICKR_PHOTO_ROOT.$this->aliasName."/".$photoId."/in/set".$albumId;
+ $photo['photoUrl'] = $this->userRoot."&album=".$albumId."&photo=".$photoId."&secret=".$photoSecret;
+
+ array_push( $photos, $photo);
+ }
+ } else {
+ $photo = Array();
+
+ $photoId = $tree['RSP']['PHOTOSET']['PHOTO']['ATTRIBUTES']['ID'];
+ $photoSecret =$tree['RSP']['PHOTOSET']['PHOTO']['ATTRIBUTES']['SECRET'];
+
+ $photo['thumbnailUrl'] = FLICKR_PHOTO_ROOT.$photoId."_".$photoSecret."_".$this->photoThumbnailSize.".jpg";
+ $photo['flickrUrl'] = FLICKR_PHOTO_ROOT.$this->aliasName."/".$photoId."/in/set".$albumId;
+ $photo['photoUrl'] = $this->userRoot."&album=".$albumId."&photo=".$photoId."&secret=".$photoSecret;
+
+ array_push( $photos, $photo);
+ }
+ return $photos;
+ }
+
+ /**
+ * Get the photo info from specific photo
+ */
+ function getPhotoInfo($photoId, $photoSecret)
+ {
+ $apiUrl = FLICKR_GET_PHOTOINFO.FLICKR_API_KEY;
+ if ($this->showPrivate == 1)
+ $apiUrl .= '&photo_id=' . $photoId;
+ else
+ $apiUrl .= '&email=' . $this->email . '&password=' . $this->password . '&photo_id=' . $photoId;
+
+ $rg = new RawRequestGenerator($this->blogInfo);
+ $this->userRoot = $rg->templatePage( "flickr" );
+
+ $data = $this->cached_get_file_contents($apiUrl, 'r', $this->expiredTime, $this->cacheFolder);
+ $parser = new XMLParser($data, 'raw', 1);
+ $tree = $parser->getTree();
+
+ $photo = Array();
+
+ $photo['date'] = $tree['RSP']['PHOTO']['ATTRIBUTES']['DATEUPLOADED'];
+ $photo['title'] = $tree['RSP']['PHOTO']['TITLE']['VALUE'];
+ $photo['description'] = $tree['RSP']['PHOTO']['DESCRIPTION']['VALUE'];
+ $photo['comments'] = $tree['RSP']['PHOTO']['COMMENTS']['VALUE'];
+
+ $photo['resizeimageUrl'] = FLICKR_PHOTO_ROOT.$photoId."_".$photoSecret.".jpg";
+ $photo['originalimageUrl'] = FLICKR_PHOTO_ROOT.$photoId."_".$photoSecret."_o.jpg";
+ $photo['flickrUrl'] = FLICKR_PHOTO_ROOT.$this->aliasName."/".$photoId;
+
+ $tagCount = count($tree['RSP']['PHOTO']['TAGS']['TAG']);
+
+ if ($tree['RSP']['PHOTO']['TAGS']['TAG'][0] != NULL) {
+ for ($i = 0; $i < $tagCount; $i=$i+1) {
+ $photo['tags'][$i]['tagName'] = $tree['RSP']['PHOTO']['TAGS']['TAG'][$i]['VALUE'];
+ $photo['tags'][$i]['tagUrl'] = FLICKR_PHOTO_ROOT."tags/".$tree['RSP']['PHOTO']['TAGS']['TAG'][$i]['VALUE'];
+ }
+ } else {
+ $photo['tags'][0]['tagName'] = $tree['RSP']['PHOTO']['TAGS']['TAG']['VALUE'];
+ $photo['tags'][0]['tagUrl'] = FLICKR_PHOTO_ROOT."tags/".$tree['RSP']['PHOTO']['TAGS']['TAG']['VALUE'];
+ }
+
+ $noteCount = count($tree['RSP']['PHOTO']['NOTES']['NOTE']);
+
+ if ($this->showNote) {
+ if ($tree['RSP']['PHOTO']['NOTES']['NOTE'][0] != NULL) {
+ for ($i = 0; $i < $noteCount; $i=$i+1) {
+ $photo['notes'][$i]['noteDesc'] = $tree['RSP']['PHOTO']['NOTES']['NOTE'][$i]['VALUE'];
+ $photo['notes'][$i]['noteX'] = $tree['RSP']['PHOTO']['NOTES']['NOTE'][$i]['ATTRIBUTES']['X'];
+ $photo['notes'][$i]['noteY'] = $tree['RSP']['PHOTO']['NOTES']['NOTE'][$i]['ATTRIBUTES']['Y'];
+ $photo['notes'][$i]['noteW'] = $tree['RSP']['PHOTO']['NOTES']['NOTE'][$i]['ATTRIBUTES']['W'];
+ $photo['notes'][$i]['noteH'] = $tree['RSP']['PHOTO']['NOTES']['NOTE'][$i]['ATTRIBUTES']['H'];
+ }
+ } else {
+ $photo['notes'][0]['noteDesc'] = $tree['RSP']['PHOTO']['NOTES']['NOTE']['VALUE'];
+ $photo['notes'][0]['noteX'] = $tree['RSP']['PHOTO']['NOTES']['NOTE']['ATTRIBUTES']['X'];
+ $photo['notes'][0]['noteY'] = $tree['RSP']['PHOTO']['NOTES']['NOTE']['ATTRIBUTES']['Y'];
+ $photo['notes'][0]['noteW'] = $tree['RSP']['PHOTO']['NOTES']['NOTE']['ATTRIBUTES']['W'];
+ $photo['notes'][0]['noteH'] = $tree['RSP']['PHOTO']['NOTES']['NOTE']['ATTRIBUTES']['H'];
+ }
+ }
+
+ return $photo;
+ }
+
+ /**
+ * Function that reads file from the cache if it is younger than a certain age
+ * and otherwise grabs a fresh copy of it from remote source
+ */
+ function cached_get_file_contents ($file, $file_mode, $cache_timeout = 3600, $cache_path = '../', $debug = false)
+ {
+ // Clear file stats so we get an accurate file creation time for cache files
+ clearstatcache();
+
+ // Path to cached file
+ $cache_filename = $cache_path .'/' . urlencode($file) . ".cached";
+
+ if ($debug)
+ {
+ print "local_cache creation_time =" . @filemtime($cache_filename) . " actual time = " . time() . " timeout = " . $timeout_seconds ."\n";
+ }
+
+ if (( @file_exists($cache_filename) && (( @filemtime($cache_filename) + $cache_timeout) > ( time())))) // If file exists and is young enough then do nothing because it will return file contents of cache
+ {
+ if ($debug)
+ {
+ print "using cached file ($cache_filename)\n";
+ }
+ }
+ else // If file doesn't exist or is too old get a fresh copy from remote source
+ {
+ if ($debug)
+ {
+ print "cacheing file ($file) to local ($cache_filename)\n";
+ }
+
+ $f = @fopen($file,"r"); // Open remote source file
+ if (!$f) // Remote file couldn't be opened
+ {
+ return @file_get_contents ($cache_filename); // Return the file contents from the cache
+ }
+ $f2 = @fopen($cache_filename,"w+"); // Open local cache file
+ while ($r = @fread($f,8192)) // Loop through remote source file
+ {
+ @fwrite($f2,$r); // Write to the local cache
+ }
+ @fclose($f2);
+ @fclose($f);
+ }
+
+ return file_get_contents ($cache_filename); // Return the file contents from the cache
+ }
+ }
+?>
Added: plugins/trunk/flickr/readme.txt
===================================================================
--- plugins/trunk/flickr/readme.txt 2005-01-24 08:57:44 UTC (rev 815)
+++ plugins/trunk/flickr/readme.txt 2005-01-24 10:18:46 UTC (rev 816)
@@ -0,0 +1,10 @@
+Plugin: Flickr
+Author: Mark Wu
+Release Date: 2005/01/24
+Version: 1.0
+
+This plugin offers you to integrate with Flickr service.
+The plugin is inspired by Wordpress Flickr Gallery Plugin written by Ray.
+
+Example:
+Copy the install\flickr.template to your template folder.
\ No newline at end of file
Added: plugins/trunk/flickr/templates/flickr.template
===================================================================
--- plugins/trunk/flickr/templates/flickr.template 2005-01-24 08:57:44 UTC (rev 815)
+++ plugins/trunk/flickr/templates/flickr.template 2005-01-24 10:18:46 UTC (rev 816)
@@ -0,0 +1,68 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=Flickr title=$locale->tr("flickr_plugin")}
+<form name="flickrPluginConfig" method="post">
+ <fieldset class="inputField">
+ <legend>{$locale->tr("flickr_plugin_configuration")}</legend>
+ <div class="field">
+ <label for="pluginEnabled">{$locale->tr("flickr_plugin_enabled")}</label>
+ <input class="checkbox" type="checkbox" name="pluginEnabled" id="pluginEnabled" {if $pluginEnabled} checked="checked" {/if} value="1" /><br/>
+ </div>
+ <div class="field">
+ <label for="email">{$locale->tr("flickr_email")}</label>
+ <span class="required">*</span>
+ <input class="text" type="text" name="email" id="email" value="{$email}" width="10" />
+ </div>
+ <div class="field">
+ <label for="password">{$locale->tr("flickr_password")}</label>
+ <span class="required">*</span>
+ <input class="password" type="password" name="password" id="password" value="{$password}" width="10" />
+ </div>
+ <div class="field">
+ <label for="aliasName">{$locale->tr("flickr_aliasname")}</label>
+ <span class="required">*</span>
+ <input class="text" type="text" name="aliasName" id="aliasName" value="{$aliasName}" width="10" />
+ </div>
+ <div class="field">
+ <label for="albumThumbnailSize">{$locale->tr("flickr_albumthumbnailsize")}</label>
+ <select name="albumThumbnailSize" id="albumThumbnailSize">
+ <option value="s" {if $albumThumbnailSize=="s"}selected="selected"{/if}>75x75</option>
+ <option value="t" {if $albumThumbnailSize=="t"}selected="selected"{/if}>100x75</option>
+ <option value="m" {if $albumThumbnailSize=="m"}selected="selected"{/if}>240x180</option>
+ </select><br/>
+ </div>
+ <div class="field">
+ <label for="photoThumbnailSize">{$locale->tr("flickr_photothumbnailsize")}</label>
+ <select name="photoThumbnailSize" id="photoThumbnailSize">
+ <option value="s" {if $photoThumbnailSize=="s"}selected="selected"{/if}>75x75</option>
+ <option value="t" {if $photoThumbnailSize=="t"}selected="selected"{/if}>100x75</option>
+ <option value="m" {if $photoThumbnailSize=="m"}selected="selected"{/if}>240x180</option>
+ </select><br/>
+ </div>
+ <div class="field">
+ <label for="showPrivate">{$locale->tr("flickr_showprivate")}</label>
+ <select name="showPrivate" id="showPrivate">
+ <option value="0" {if $showPrivate==0}selected="selected"{/if}>{$locale->tr("flickr_no")}</option>
+ <option value="1" {if $showPrivate==1}selected="selected"{/if}>{$locale->tr("flickr_yes")}</option>
+ </select><br/>
+ </div>
+ <div class="field">
+ <label for="showNote">{$locale->tr("flickr_shownote")}</label>
+ <select name="showNote" id="showPrivate">
+ <option value="0" {if $showNote==0}selected="selected"{/if}>{$locale->tr("flickr_no")}</option>
+ <option value="1" {if $showNote==1}selected="selected"{/if}>{$locale->tr("flickr_yes")}</option>
+ </select><br/>
+ </div>
+ <div class="field">
+ <label for="expiredTime">{$locale->tr("flickr_expiredtime")}</label>
+ <span class="required">*</span>
+ <input class="text" type="text" name="expiredTime" id="expiredTime" value="{$expiredTime}" width="10" />
+ </div>
+ </fieldset>
+ <br/>
+ <div class="buttons">
+ <input type="hidden" name="op" value="updateFlickrConfig" />
+ <input type="submit" name="{$locale->tr("update_settings")}" value="{$locale->tr("update")}" />
+ </div>
+</form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file
More information about the pLog-svn
mailing list